Skip to content

Commit

Permalink
fix: "clause"."hidden"
Browse files Browse the repository at this point in the history
  • Loading branch information
ledouxm committed Jul 8, 2024
1 parent d20b7a6 commit 85fec2c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 9 deletions.
1 change: 0 additions & 1 deletion db/migrations/04-add_chips_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ CREATE TABLE clause(
,value text NOT NULL
,udap_id text
,text text NOT NULL
,hidden boolean
, PRIMARY KEY (key, value, udap_id)
);

Expand Down
1 change: 1 addition & 0 deletions db/migrations/903-fix_clausev1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE clause ADD COLUMN "hidden" BOOLEAN;
23 changes: 19 additions & 4 deletions packages/electric-client/src/generated/client/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ export default [
},
{
"statements": [
"CREATE TABLE \"clause\" (\n \"key\" TEXT NOT NULL,\n \"value\" TEXT NOT NULL,\n \"udap_id\" TEXT NOT NULL,\n \"text\" TEXT NOT NULL,\n \"hidden\" INTEGER,\n CONSTRAINT \"clause_pkey\" PRIMARY KEY (\"key\", \"value\", \"udap_id\")\n) WITHOUT ROWID;\n",
"CREATE TABLE \"clause\" (\n \"key\" TEXT NOT NULL,\n \"value\" TEXT NOT NULL,\n \"udap_id\" TEXT NOT NULL,\n \"text\" TEXT NOT NULL,\n CONSTRAINT \"clause_pkey\" PRIMARY KEY (\"key\", \"value\", \"udap_id\")\n) WITHOUT ROWID;\n",
"INSERT OR IGNORE INTO _electric_trigger_settings (namespace, tablename, flag) VALUES ('main', 'clause', 1);",
"DROP TRIGGER IF EXISTS update_ensure_main_clause_primarykey;",
"CREATE TRIGGER update_ensure_main_clause_primarykey\n BEFORE UPDATE ON \"main\".\"clause\"\nBEGIN\n SELECT\n CASE\n WHEN old.\"key\" != new.\"key\" THEN\n \t\tRAISE (ABORT, 'cannot change the value of column key as it belongs to the primary key')\n WHEN old.\"udap_id\" != new.\"udap_id\" THEN\n \t\tRAISE (ABORT, 'cannot change the value of column udap_id as it belongs to the primary key')\n WHEN old.\"value\" != new.\"value\" THEN\n \t\tRAISE (ABORT, 'cannot change the value of column value as it belongs to the primary key')\n END;\nEND;",
"DROP TRIGGER IF EXISTS insert_main_clause_into_oplog;",
"CREATE TRIGGER insert_main_clause_into_oplog\n AFTER INSERT ON \"main\".\"clause\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'clause')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'clause', 'INSERT', json_patch('{}', json_object('key', new.\"key\", 'udap_id', new.\"udap_id\", 'value', new.\"value\")), json_object('hidden', new.\"hidden\", 'key', new.\"key\", 'text', new.\"text\", 'udap_id', new.\"udap_id\", 'value', new.\"value\"), NULL, NULL);\nEND;",
"CREATE TRIGGER insert_main_clause_into_oplog\n AFTER INSERT ON \"main\".\"clause\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'clause')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'clause', 'INSERT', json_patch('{}', json_object('key', new.\"key\", 'udap_id', new.\"udap_id\", 'value', new.\"value\")), json_object('key', new.\"key\", 'text', new.\"text\", 'udap_id', new.\"udap_id\", 'value', new.\"value\"), NULL, NULL);\nEND;",
"DROP TRIGGER IF EXISTS update_main_clause_into_oplog;",
"CREATE TRIGGER update_main_clause_into_oplog\n AFTER UPDATE ON \"main\".\"clause\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'clause')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'clause', 'UPDATE', json_patch('{}', json_object('key', new.\"key\", 'udap_id', new.\"udap_id\", 'value', new.\"value\")), json_object('hidden', new.\"hidden\", 'key', new.\"key\", 'text', new.\"text\", 'udap_id', new.\"udap_id\", 'value', new.\"value\"), json_object('hidden', old.\"hidden\", 'key', old.\"key\", 'text', old.\"text\", 'udap_id', old.\"udap_id\", 'value', old.\"value\"), NULL);\nEND;",
"CREATE TRIGGER update_main_clause_into_oplog\n AFTER UPDATE ON \"main\".\"clause\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'clause')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'clause', 'UPDATE', json_patch('{}', json_object('key', new.\"key\", 'udap_id', new.\"udap_id\", 'value', new.\"value\")), json_object('key', new.\"key\", 'text', new.\"text\", 'udap_id', new.\"udap_id\", 'value', new.\"value\"), json_object('key', old.\"key\", 'text', old.\"text\", 'udap_id', old.\"udap_id\", 'value', old.\"value\"), NULL);\nEND;",
"DROP TRIGGER IF EXISTS delete_main_clause_into_oplog;",
"CREATE TRIGGER delete_main_clause_into_oplog\n AFTER DELETE ON \"main\".\"clause\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'clause')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'clause', 'DELETE', json_patch('{}', json_object('key', old.\"key\", 'udap_id', old.\"udap_id\", 'value', old.\"value\")), NULL, json_object('hidden', old.\"hidden\", 'key', old.\"key\", 'text', old.\"text\", 'udap_id', old.\"udap_id\", 'value', old.\"value\"), NULL);\nEND;"
"CREATE TRIGGER delete_main_clause_into_oplog\n AFTER DELETE ON \"main\".\"clause\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'clause')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'clause', 'DELETE', json_patch('{}', json_object('key', old.\"key\", 'udap_id', old.\"udap_id\", 'value', old.\"value\")), NULL, json_object('key', old.\"key\", 'text', old.\"text\", 'udap_id', old.\"udap_id\", 'value', old.\"value\"), NULL);\nEND;"
],
"version": "4"
},
Expand Down Expand Up @@ -147,5 +147,20 @@ export default [
"CREATE TRIGGER delete_main_clause_v2_into_oplog\n AFTER DELETE ON \"main\".\"clause_v2\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'clause_v2')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'clause_v2', 'DELETE', json_patch('{}', json_object('id', old.\"id\")), NULL, json_object('id', old.\"id\", 'key', old.\"key\", 'position', old.\"position\", 'text', old.\"text\", 'udap_id', old.\"udap_id\", 'value', old.\"value\"), NULL);\nEND;"
],
"version": "902"
},
{
"statements": [
"ALTER TABLE \"clause\" ADD COLUMN \"hidden\" INTEGER;\n",
"INSERT OR IGNORE INTO _electric_trigger_settings (namespace, tablename, flag) VALUES ('main', 'clause', 1);",
"DROP TRIGGER IF EXISTS update_ensure_main_clause_primarykey;",
"CREATE TRIGGER update_ensure_main_clause_primarykey\n BEFORE UPDATE ON \"main\".\"clause\"\nBEGIN\n SELECT\n CASE\n WHEN old.\"key\" != new.\"key\" THEN\n \t\tRAISE (ABORT, 'cannot change the value of column key as it belongs to the primary key')\n WHEN old.\"udap_id\" != new.\"udap_id\" THEN\n \t\tRAISE (ABORT, 'cannot change the value of column udap_id as it belongs to the primary key')\n WHEN old.\"value\" != new.\"value\" THEN\n \t\tRAISE (ABORT, 'cannot change the value of column value as it belongs to the primary key')\n END;\nEND;",
"DROP TRIGGER IF EXISTS insert_main_clause_into_oplog;",
"CREATE TRIGGER insert_main_clause_into_oplog\n AFTER INSERT ON \"main\".\"clause\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'clause')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'clause', 'INSERT', json_patch('{}', json_object('key', new.\"key\", 'udap_id', new.\"udap_id\", 'value', new.\"value\")), json_object('hidden', new.\"hidden\", 'key', new.\"key\", 'text', new.\"text\", 'udap_id', new.\"udap_id\", 'value', new.\"value\"), NULL, NULL);\nEND;",
"DROP TRIGGER IF EXISTS update_main_clause_into_oplog;",
"CREATE TRIGGER update_main_clause_into_oplog\n AFTER UPDATE ON \"main\".\"clause\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'clause')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'clause', 'UPDATE', json_patch('{}', json_object('key', new.\"key\", 'udap_id', new.\"udap_id\", 'value', new.\"value\")), json_object('hidden', new.\"hidden\", 'key', new.\"key\", 'text', new.\"text\", 'udap_id', new.\"udap_id\", 'value', new.\"value\"), json_object('hidden', old.\"hidden\", 'key', old.\"key\", 'text', old.\"text\", 'udap_id', old.\"udap_id\", 'value', old.\"value\"), NULL);\nEND;",
"DROP TRIGGER IF EXISTS delete_main_clause_into_oplog;",
"CREATE TRIGGER delete_main_clause_into_oplog\n AFTER DELETE ON \"main\".\"clause\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'clause')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'clause', 'DELETE', json_patch('{}', json_object('key', old.\"key\", 'udap_id', old.\"udap_id\", 'value', old.\"value\")), NULL, json_object('hidden', old.\"hidden\", 'key', old.\"key\", 'text', old.\"text\", 'udap_id', old.\"udap_id\", 'value', old.\"value\"), NULL);\nEND;"
],
"version": "903"
}
]
Loading

0 comments on commit 85fec2c

Please sign in to comment.