(bug) - fix original template scripts & remove amend scripts (#3229)

* removing amend template scripts and fixing original scripts due to Brads feedback
This commit is contained in:
Eoin McAfee 2022-06-15 09:11:28 +01:00 committed by GitHub
parent 39e194ab11
commit d7e34af1de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 88 deletions

View file

@ -160,6 +160,10 @@ var migrations = []struct {
name: "create-table-template", name: "create-table-template",
stmt: createTableTemplate, stmt: createTableTemplate,
}, },
{
name: "create-index-template-namespace",
stmt: createIndexTemplateNamespace,
},
{ {
name: "alter-table-steps-add-column-step-depends-on", name: "alter-table-steps-add-column-step-depends-on",
stmt: alterTableStepsAddColumnStepDependsOn, stmt: alterTableStepsAddColumnStepDependsOn,
@ -196,10 +200,6 @@ var migrations = []struct {
name: "create-new-table-cards", name: "create-new-table-cards",
stmt: createNewTableCards, stmt: createNewTableCards,
}, },
{
name: "amend-table-templates",
stmt: amendTableTemplates,
},
} }
// Migrate performs the database migration. If the migration fails // 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 = ` var createTableTemplate = `
CREATE TABLE IF NOT EXISTS templates ( CREATE TABLE IF NOT EXISTS templates (
template_id SERIAL PRIMARY KEY template_id SERIAL PRIMARY KEY
,template_name TEXT UNIQUE ,template_name TEXT
,template_namespace VARCHAR(50) ,template_namespace VARCHAR(50)
,template_data BYTEA ,template_data BYTEA
,template_created INTEGER ,template_created INTEGER
,template_updated INTEGER ,template_updated INTEGER
,UNIQUE(template_name, template_namespace) ,UNIQUE(template_name, template_namespace)
); );
`
var createIndexTemplateNamespace = `
CREATE INDEX IF NOT EXISTS ix_template_namespace ON templates (template_namespace); 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 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;
`

View file

@ -2,7 +2,7 @@
CREATE TABLE IF NOT EXISTS templates ( CREATE TABLE IF NOT EXISTS templates (
template_id SERIAL PRIMARY KEY template_id SERIAL PRIMARY KEY
,template_name TEXT UNIQUE ,template_name TEXT
,template_namespace VARCHAR(50) ,template_namespace VARCHAR(50)
,template_data BYTEA ,template_data BYTEA
,template_created INTEGER ,template_created INTEGER
@ -10,4 +10,6 @@ CREATE TABLE IF NOT EXISTS templates (
,UNIQUE(template_name, template_namespace) ,UNIQUE(template_name, template_namespace)
); );
-- name: create-index-template-namespace
CREATE INDEX IF NOT EXISTS ix_template_namespace ON templates (template_namespace); CREATE INDEX IF NOT EXISTS ix_template_namespace ON templates (template_namespace);

View file

@ -1,4 +0,0 @@
-- name: amend-table-templates
ALTER TABLE templates
DROP CONSTRAINT templates_template_name_key;

View file

@ -160,6 +160,10 @@ var migrations = []struct {
name: "create-table-templates", name: "create-table-templates",
stmt: createTableTemplates, stmt: createTableTemplates,
}, },
{
name: "create-index-template-namespace",
stmt: createIndexTemplateNamespace,
},
{ {
name: "alter-table-steps-add-column-step-depends-on", name: "alter-table-steps-add-column-step-depends-on",
stmt: alterTableStepsAddColumnStepDependsOn, stmt: alterTableStepsAddColumnStepDependsOn,
@ -196,10 +200,6 @@ var migrations = []struct {
name: "create-new-table-cards", name: "create-new-table-cards",
stmt: createNewTableCards, stmt: createNewTableCards,
}, },
{
name: "amend-templates-table",
stmt: amendTemplatesTable,
},
} }
// Migrate performs the database migration. If the migration fails // 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 = ` var createTableTemplates = `
CREATE TABLE IF NOT EXISTS templates ( CREATE TABLE IF NOT EXISTS templates (
template_id INTEGER PRIMARY KEY AUTOINCREMENT template_id INTEGER PRIMARY KEY AUTOINCREMENT
,template_name TEXT UNIQUE ,template_name TEXT
,template_namespace TEXT COLLATE NOCASE ,template_namespace TEXT COLLATE NOCASE
,template_data BLOB ,template_data BLOB
,template_created INTEGER ,template_created INTEGER
,template_updated 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); 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 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;
`

View file

@ -2,12 +2,14 @@
CREATE TABLE IF NOT EXISTS templates ( CREATE TABLE IF NOT EXISTS templates (
template_id INTEGER PRIMARY KEY AUTOINCREMENT template_id INTEGER PRIMARY KEY AUTOINCREMENT
,template_name TEXT UNIQUE ,template_name TEXT
,template_namespace TEXT COLLATE NOCASE ,template_namespace TEXT COLLATE NOCASE
,template_data BLOB ,template_data BLOB
,template_created INTEGER ,template_created INTEGER
,template_updated 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); CREATE INDEX IF NOT EXISTS ix_template_namespace ON templates (template_namespace);

View file

@ -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;