diff --git a/store/shared/migrate/postgres/ddl_gen.go b/store/shared/migrate/postgres/ddl_gen.go index 40c5c001..d87aaf50 100644 --- a/store/shared/migrate/postgres/ddl_gen.go +++ b/store/shared/migrate/postgres/ddl_gen.go @@ -160,6 +160,10 @@ var migrations = []struct { name: "create-table-template", stmt: createTableTemplate, }, + { + name: "create-index-template-namespace", + stmt: createIndexTemplateNamespace, + }, { name: "alter-table-steps-add-column-step-depends-on", stmt: alterTableStepsAddColumnStepDependsOn, @@ -196,10 +200,6 @@ var migrations = []struct { name: "create-new-table-cards", stmt: createNewTableCards, }, - { - name: "amend-table-templates", - stmt: amendTableTemplates, - }, } // Migrate performs the database migration. If the migration fails @@ -696,14 +696,16 @@ CREATE INDEX IF NOT EXISTS ix_latest_repo ON latest (latest_repo_id); var createTableTemplate = ` CREATE TABLE IF NOT EXISTS templates ( template_id SERIAL PRIMARY KEY - ,template_name TEXT UNIQUE + ,template_name TEXT ,template_namespace VARCHAR(50) ,template_data BYTEA ,template_created INTEGER ,template_updated INTEGER ,UNIQUE(template_name, template_namespace) ); +` +var createIndexTemplateNamespace = ` CREATE INDEX IF NOT EXISTS ix_template_namespace ON templates (template_namespace); ` @@ -767,12 +769,3 @@ CREATE TABLE IF NOT EXISTS cards FOREIGN KEY (card_id) REFERENCES steps (step_id) ON DELETE CASCADE ); ` - -// -// 020_amend_table_templates.sql -// - -var amendTableTemplates = ` -ALTER TABLE templates -DROP CONSTRAINT templates_template_name_key; -` diff --git a/store/shared/migrate/postgres/files/016_create_template_tables.sql b/store/shared/migrate/postgres/files/016_create_template_tables.sql index ed7d732b..c08bb5a2 100644 --- a/store/shared/migrate/postgres/files/016_create_template_tables.sql +++ b/store/shared/migrate/postgres/files/016_create_template_tables.sql @@ -2,7 +2,7 @@ CREATE TABLE IF NOT EXISTS templates ( template_id SERIAL PRIMARY KEY - ,template_name TEXT UNIQUE + ,template_name TEXT ,template_namespace VARCHAR(50) ,template_data BYTEA ,template_created INTEGER @@ -10,4 +10,6 @@ CREATE TABLE IF NOT EXISTS templates ( ,UNIQUE(template_name, template_namespace) ); +-- name: create-index-template-namespace + CREATE INDEX IF NOT EXISTS ix_template_namespace ON templates (template_namespace); diff --git a/store/shared/migrate/postgres/files/020_amend_table_templates.sql b/store/shared/migrate/postgres/files/020_amend_table_templates.sql deleted file mode 100644 index 30b3cfbd..00000000 --- a/store/shared/migrate/postgres/files/020_amend_table_templates.sql +++ /dev/null @@ -1,4 +0,0 @@ --- name: amend-table-templates - -ALTER TABLE templates -DROP CONSTRAINT templates_template_name_key; diff --git a/store/shared/migrate/sqlite/ddl_gen.go b/store/shared/migrate/sqlite/ddl_gen.go index 76afe275..ea5db110 100644 --- a/store/shared/migrate/sqlite/ddl_gen.go +++ b/store/shared/migrate/sqlite/ddl_gen.go @@ -160,6 +160,10 @@ var migrations = []struct { name: "create-table-templates", stmt: createTableTemplates, }, + { + name: "create-index-template-namespace", + stmt: createIndexTemplateNamespace, + }, { name: "alter-table-steps-add-column-step-depends-on", stmt: alterTableStepsAddColumnStepDependsOn, @@ -196,10 +200,6 @@ var migrations = []struct { name: "create-new-table-cards", stmt: createNewTableCards, }, - { - name: "amend-templates-table", - stmt: amendTemplatesTable, - }, } // Migrate performs the database migration. If the migration fails @@ -698,14 +698,16 @@ CREATE INDEX IF NOT EXISTS ix_latest_repo ON latest (latest_repo_id); var createTableTemplates = ` CREATE TABLE IF NOT EXISTS templates ( template_id INTEGER PRIMARY KEY AUTOINCREMENT - ,template_name TEXT UNIQUE + ,template_name TEXT ,template_namespace TEXT COLLATE NOCASE ,template_data BLOB ,template_created INTEGER ,template_updated INTEGER -,UNIQUE(template_name, template_namespace) + ,UNIQUE(template_name COLLATE NOCASE, template_namespace COLLATE NOCASE) ); +` +var createIndexTemplateNamespace = ` CREATE INDEX IF NOT EXISTS ix_template_namespace ON templates (template_namespace); ` @@ -769,36 +771,3 @@ CREATE TABLE IF NOT EXISTS cards FOREIGN KEY (card_id) REFERENCES steps (step_id) ON DELETE CASCADE ); ` - -// -// 019_amend_table_templates.sql -// - -var amendTemplatesTable = ` -PRAGMA foreign_keys=off; - -BEGIN TRANSACTION; - -ALTER TABLE templates RENAME TO _templates_old; - -CREATE TABLE IF NOT EXISTS templates ( - template_id INTEGER PRIMARY KEY AUTOINCREMENT - ,template_name TEXT - ,template_namespace TEXT COLLATE NOCASE - ,template_data BLOB - ,template_created INTEGER - ,template_updated INTEGER - ,UNIQUE(template_name, template_namespace) -); - -INSERT INTO templates (template_id, template_name, template_namespace, template_data, template_created, template_updated) -SELECT template_id, template_name, template_namespace, template_data, template_created, template_updated -FROM _templates_old; - -COMMIT; - -CREATE INDEX IF NOT EXISTS ix_template_namespace ON templates (template_namespace); -DROP TABLE _templates_old; - -PRAGMA foreign_keys=on; -` diff --git a/store/shared/migrate/sqlite/files/015_create_template_tables.sql b/store/shared/migrate/sqlite/files/015_create_template_tables.sql index 9db2af1c..bb73f960 100644 --- a/store/shared/migrate/sqlite/files/015_create_template_tables.sql +++ b/store/shared/migrate/sqlite/files/015_create_template_tables.sql @@ -2,12 +2,14 @@ CREATE TABLE IF NOT EXISTS templates ( template_id INTEGER PRIMARY KEY AUTOINCREMENT - ,template_name TEXT UNIQUE + ,template_name TEXT ,template_namespace TEXT COLLATE NOCASE ,template_data BLOB ,template_created INTEGER ,template_updated INTEGER -,UNIQUE(template_name, template_namespace) + ,UNIQUE(template_name COLLATE NOCASE, template_namespace COLLATE NOCASE) ); +-- name: create-index-template-namespace + CREATE INDEX IF NOT EXISTS ix_template_namespace ON templates (template_namespace); diff --git a/store/shared/migrate/sqlite/files/019_amend_table_templates.sql b/store/shared/migrate/sqlite/files/019_amend_table_templates.sql deleted file mode 100644 index 16b094d0..00000000 --- a/store/shared/migrate/sqlite/files/019_amend_table_templates.sql +++ /dev/null @@ -1,28 +0,0 @@ --- name: amend-templates-table - -PRAGMA foreign_keys=off; - -BEGIN TRANSACTION; - -ALTER TABLE templates RENAME TO _templates_old; - -CREATE TABLE IF NOT EXISTS templates ( - template_id INTEGER PRIMARY KEY AUTOINCREMENT - ,template_name TEXT - ,template_namespace TEXT COLLATE NOCASE - ,template_data BLOB - ,template_created INTEGER - ,template_updated INTEGER - ,UNIQUE(template_name, template_namespace) -); - -INSERT INTO templates (template_id, template_name, template_namespace, template_data, template_created, template_updated) -SELECT template_id, template_name, template_namespace, template_data, template_created, template_updated -FROM _templates_old; - -COMMIT; - -CREATE INDEX IF NOT EXISTS ix_template_namespace ON templates (template_namespace); -DROP TABLE _templates_old; - -PRAGMA foreign_keys=on; \ No newline at end of file