Changeset: 2e4d55dd7aa2 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2e4d55dd7aa2
Modified Files:
        sql/backends/monet5/sql_upgrades.c
        sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.int128
        
sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.powerpc64.int128
        sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out
        sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.32bit
        sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.int128
        sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.powerpc64
        sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.powerpc64.int128
        sql/test/emptydb-upgrade-hge/Tests/upgrade.stable.out.int128
        sql/test/emptydb-upgrade/Tests/upgrade.stable.out
        sql/test/emptydb-upgrade/Tests/upgrade.stable.out.32bit
        sql/test/emptydb-upgrade/Tests/upgrade.stable.out.int128
        sql/test/emptydb/Tests/check.stable.out
        sql/test/emptydb/Tests/check.stable.out.int128
        sql/test/testdb-upgrade-chain-hge/Tests/upgrade.stable.out.int128
        sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out
        sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out.32bit
        sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out.int128
        sql/test/testdb-upgrade-hge/Tests/upgrade.stable.out.int128
        sql/test/testdb-upgrade/Tests/upgrade.stable.out
        sql/test/testdb-upgrade/Tests/upgrade.stable.out.32bit
        sql/test/testdb-upgrade/Tests/upgrade.stable.out.int128
Branch: default
Log Message:

Fix upgrade for default branch.


diffs (truncated from 782 to 300 lines):

diff --git a/sql/backends/monet5/sql_upgrades.c 
b/sql/backends/monet5/sql_upgrades.c
--- a/sql/backends/monet5/sql_upgrades.c
+++ b/sql/backends/monet5/sql_upgrades.c
@@ -2766,6 +2766,78 @@ sql_update_jun2020_bam(Client c, mvc *m,
        return err;
 }
 
+static str
+sql_update_default(Client c, mvc *sql, const char *prev_schema)
+{
+       size_t bufsize = 1024, pos = 0;
+       char *err = NULL, *buf = GDKmalloc(bufsize);
+       sql_schema *sys = mvc_bind_schema(sql, "sys");
+       res_table *output;
+       BAT *b;
+
+       if (buf == NULL)
+               throw(SQL, __func__, SQLSTATE(HY013) MAL_MALLOC_FAIL);
+
+       /* if column 6 of sys.queue is named "progress" we need to update */
+       pos += snprintf(buf + pos, bufsize - pos,
+                       "select name from sys._columns where table_id = (select 
id from sys._tables where name = 'queue' and schema_id = (select id from 
sys.schemas where name = 'sys')) and number = 6;\n");
+       err = SQLstatementIntern(c, &buf, "update", true, false, &output);
+       if (err) {
+               GDKfree(buf);
+               return err;
+       }
+       b = BATdescriptor(output->cols[0].b);
+       if (b) {
+               BATiter bi = bat_iterator(b);
+               if (BATcount(b) > 0 && strcmp(BUNtail(bi, 0), "progress") == 0) 
{
+                       pos = 0;
+                       pos += snprintf(buf + pos, bufsize - pos,
+                                       "set schema \"sys\";\n");
+
+                       /* 26_sysmon */
+                       sql_table *t;
+                       t = mvc_bind_table(sql, sys, "queue");
+                       t->system = 0; /* make it non-system else the drop view 
will fail */
+
+                       pos += snprintf(buf + pos, bufsize - pos,
+                                       "drop view sys.queue;\n"
+                                       "drop function sys.queue;\n"
+                                       "create function sys.queue()\n"
+                                       "returns table(\n"
+                                       "\"tag\" bigint,\n"
+                                       "\"sessionid\" int,\n"
+                                       "\"username\" string,\n"
+                                       "\"started\" timestamp,\n"
+                                       "\"status\" string,\n"
+                                       "\"query\" string,\n"
+                                       "\"finished\" timestamp,\n"
+                                       "\"workers\" int,\n"
+                                       "\"memory\" int)\n"
+                                       " external name sql.sysmon_queue;\n"
+                                       "grant execute on function sys.queue to 
public;\n"
+                                       "create view sys.queue as select * from 
sys.queue();\n"
+                                       "grant select on sys.queue to 
public;\n");
+
+                       pos += snprintf(buf + pos, bufsize - pos,
+                                       "update sys.functions set system = true 
where schema_id = (select id from sys.schemas where name = 'sys')"
+                                       " and name = 'queue' and type = %d;\n", 
(int) F_UNION);
+                       pos += snprintf(buf + pos, bufsize - pos,
+                                       "update sys._tables set system = true 
where schema_id = (select id from sys.schemas where name = 'sys')"
+                                       " and name = 'queue';\n");
+
+                       pos += snprintf(buf + pos, bufsize - pos, "set schema 
\"%s\";\n", prev_schema);
+                       assert(pos < bufsize);
+
+                       printf("Running database upgrade commands:\n%s\n", buf);
+                       err = SQLstatementIntern(c, &buf, "update", true, 
false, NULL);
+               }
+               BBPunfix(b->batCacheid);
+       }
+       res_table_destroy(output);
+       GDKfree(buf);
+       return err;             /* usually MAL_SUCCEED */
+}
+
 int
 SQLupgrades(Client c, mvc *m)
 {
@@ -3038,6 +3110,12 @@ SQLupgrades(Client c, mvc *m)
                return -1;
        }
 
+       if ((err = sql_update_default(c, m, prev_schema)) != NULL) {
+               TRC_CRITICAL(SQL_PARSER, "%s\n", err);
+               freeException(err);
+               return -1;
+       }
+
        GDKfree(prev_schema);
        return 0;
 }
diff --git a/sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.int128 
b/sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.int128
--- a/sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.int128
+++ b/sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.int128
@@ -6419,6 +6419,29 @@ drop table bam.files;
 drop schema bam;
 set schema "sys";
 
+Running database upgrade commands:
+set schema "sys";
+drop view sys.queue;
+drop function sys.queue;
+create function sys.queue()
+returns table(
+"tag" bigint,
+"sessionid" int,
+"username" string,
+"started" timestamp,
+"status" string,
+"query" string,
+"finished" timestamp,
+"workers" int,
+"memory" int)
+ external name sql.sysmon_queue;
+grant execute on function sys.queue to public;
+create view sys.queue as select * from sys.queue();
+grant select on sys.queue to public;
+update sys.functions set system = true where schema_id = (select id from 
sys.schemas where name = 'sys') and name = 'queue' and type = 5;
+update sys._tables set system = true where schema_id = (select id from 
sys.schemas where name = 'sys') and name = 'queue';
+set schema "sys";
+
 # MonetDB/SQL module loaded
 
 # 15:17:55 >  
diff --git 
a/sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.powerpc64.int128 
b/sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.powerpc64.int128
--- 
a/sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.powerpc64.int128
+++ 
b/sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.powerpc64.int128
@@ -6419,6 +6419,29 @@ drop table bam.files;
 drop schema bam;
 set schema "sys";
 
+Running database upgrade commands:
+set schema "sys";
+drop view sys.queue;
+drop function sys.queue;
+create function sys.queue()
+returns table(
+"tag" bigint,
+"sessionid" int,
+"username" string,
+"started" timestamp,
+"status" string,
+"query" string,
+"finished" timestamp,
+"workers" int,
+"memory" int)
+ external name sql.sysmon_queue;
+grant execute on function sys.queue to public;
+create view sys.queue as select * from sys.queue();
+grant select on sys.queue to public;
+update sys.functions set system = true where schema_id = (select id from 
sys.schemas where name = 'sys') and name = 'queue' and type = 5;
+update sys._tables set system = true where schema_id = (select id from 
sys.schemas where name = 'sys') and name = 'queue';
+set schema "sys";
+
 # MonetDB/SQL module loaded
 
 # 15:17:55 >  
diff --git a/sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out 
b/sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out
--- a/sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out
+++ b/sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out
@@ -5605,6 +5605,29 @@ drop table bam.files;
 drop schema bam;
 set schema "sys";
 
+Running database upgrade commands:
+set schema "sys";
+drop view sys.queue;
+drop function sys.queue;
+create function sys.queue()
+returns table(
+"tag" bigint,
+"sessionid" int,
+"username" string,
+"started" timestamp,
+"status" string,
+"query" string,
+"finished" timestamp,
+"workers" int,
+"memory" int)
+ external name sql.sysmon_queue;
+grant execute on function sys.queue to public;
+create view sys.queue as select * from sys.queue();
+grant select on sys.queue to public;
+update sys.functions set system = true where schema_id = (select id from 
sys.schemas where name = 'sys') and name = 'queue' and type = 5;
+update sys._tables set system = true where schema_id = (select id from 
sys.schemas where name = 'sys') and name = 'queue';
+set schema "sys";
+
 # MonetDB/SQL module loaded
 
 # 15:55:37 >  
diff --git a/sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.32bit 
b/sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.32bit
--- a/sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.32bit
+++ b/sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.32bit
@@ -5605,6 +5605,29 @@ drop table bam.files;
 drop schema bam;
 set schema "sys";
 
+Running database upgrade commands:
+set schema "sys";
+drop view sys.queue;
+drop function sys.queue;
+create function sys.queue()
+returns table(
+"tag" bigint,
+"sessionid" int,
+"username" string,
+"started" timestamp,
+"status" string,
+"query" string,
+"finished" timestamp,
+"workers" int,
+"memory" int)
+ external name sql.sysmon_queue;
+grant execute on function sys.queue to public;
+create view sys.queue as select * from sys.queue();
+grant select on sys.queue to public;
+update sys.functions set system = true where schema_id = (select id from 
sys.schemas where name = 'sys') and name = 'queue' and type = 5;
+update sys._tables set system = true where schema_id = (select id from 
sys.schemas where name = 'sys') and name = 'queue';
+set schema "sys";
+
 # MonetDB/SQL module loaded
 
 # 16:02:52 >  
diff --git a/sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.int128 
b/sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.int128
--- a/sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.int128
+++ b/sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.int128
@@ -6463,6 +6463,29 @@ drop table bam.files;
 drop schema bam;
 set schema "sys";
 
+Running database upgrade commands:
+set schema "sys";
+drop view sys.queue;
+drop function sys.queue;
+create function sys.queue()
+returns table(
+"tag" bigint,
+"sessionid" int,
+"username" string,
+"started" timestamp,
+"status" string,
+"query" string,
+"finished" timestamp,
+"workers" int,
+"memory" int)
+ external name sql.sysmon_queue;
+grant execute on function sys.queue to public;
+create view sys.queue as select * from sys.queue();
+grant select on sys.queue to public;
+update sys.functions set system = true where schema_id = (select id from 
sys.schemas where name = 'sys') and name = 'queue' and type = 5;
+update sys._tables set system = true where schema_id = (select id from 
sys.schemas where name = 'sys') and name = 'queue';
+set schema "sys";
+
 # MonetDB/SQL module loaded
 
 # 16:53:35 >  
diff --git a/sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.powerpc64 
b/sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.powerpc64
--- a/sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.powerpc64
+++ b/sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.powerpc64
@@ -5605,6 +5605,29 @@ drop table bam.files;
 drop schema bam;
 set schema "sys";
 
+Running database upgrade commands:
+set schema "sys";
+drop view sys.queue;
+drop function sys.queue;
+create function sys.queue()
+returns table(
+"tag" bigint,
+"sessionid" int,
+"username" string,
+"started" timestamp,
+"status" string,
+"query" string,
+"finished" timestamp,
+"workers" int,
+"memory" int)
+ external name sql.sysmon_queue;
+grant execute on function sys.queue to public;
+create view sys.queue as select * from sys.queue();
+grant select on sys.queue to public;
+update sys.functions set system = true where schema_id = (select id from 
sys.schemas where name = 'sys') and name = 'queue' and type = 5;
+update sys._tables set system = true where schema_id = (select id from 
sys.schemas where name = 'sys') and name = 'queue';
+set schema "sys";
+
 # MonetDB/SQL module loaded
 
 # 15:55:37 >  
diff --git 
a/sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.powerpc64.int128 
b/sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.powerpc64.int128
--- a/sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.powerpc64.int128
+++ b/sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.powerpc64.int128
@@ -6463,6 +6463,29 @@ drop table bam.files;
 drop schema bam;
 set schema "sys";
 
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to