From a4e2240e056842fae12f02b2c381adc3baa5ad15 Mon Sep 17 00:00:00 2001 From: martinrotter Date: Tue, 14 Mar 2017 07:40:49 +0100 Subject: [PATCH] More complete SQL stuff for #102. --- resources/sql/db_init_mysql.sql | 11 +++++++++++ resources/sql/db_init_sqlite.sql | 13 +++++++++++++ resources/sql/db_update_mysql_7_8.sql | 9 +++++++++ resources/sql/db_update_sqlite_7_8.sql | 11 +++++++++++ 4 files changed, 44 insertions(+) diff --git a/resources/sql/db_init_mysql.sql b/resources/sql/db_init_mysql.sql index 571674cca..572da652d 100644 --- a/resources/sql/db_init_mysql.sql +++ b/resources/sql/db_init_mysql.sql @@ -113,5 +113,16 @@ CREATE TABLE IF NOT EXISTS Labels ( custom_id TEXT, custom_hash TEXT, + FOREIGN KEY (account_id) REFERENCES Accounts (id) +); +-- ! +DROP TABLE IF EXISTS LabelsInMessages; +-- ! +CREATE TABLE IF NOT EXISTS LabelsInMessages ( + id INTEGER AUTO_INCREMENT PRIMARY KEY, + message_custom_id TEXT NOT NULL, + label_custom_id TEXT NOT NULL, + account_id INTEGER NOT NULL, + FOREIGN KEY (account_id) REFERENCES Accounts (id) ); \ No newline at end of file diff --git a/resources/sql/db_init_sqlite.sql b/resources/sql/db_init_sqlite.sql index 304c707c8..0eaa093ac 100644 --- a/resources/sql/db_init_sqlite.sql +++ b/resources/sql/db_init_sqlite.sql @@ -108,5 +108,18 @@ CREATE TABLE IF NOT EXISTS Labels ( custom_id TEXT, custom_hash TEXT, + FOREIGN KEY (account_id) REFERENCES Accounts (id) +); +-- ! +DROP TABLE IF EXISTS LabelsInMessages; +-- ! +CREATE TABLE IF NOT EXISTS LabelsInMessages ( + id INTEGER PRIMARY KEY, + message_custom_id TEXT NOT NULL, + label_custom_id TEXT NOT NULL, + account_id INTEGER NOT NULL, + + FOREIGN KEY (message_custom_id) REFERENCES Messages (custom_id), + FOREIGN KEY (label_custom_id) REFERENCES Labels (custom_id), FOREIGN KEY (account_id) REFERENCES Accounts (id) ); \ No newline at end of file diff --git a/resources/sql/db_update_mysql_7_8.sql b/resources/sql/db_update_mysql_7_8.sql index 61d95242f..ab59d647e 100755 --- a/resources/sql/db_update_mysql_7_8.sql +++ b/resources/sql/db_update_mysql_7_8.sql @@ -11,4 +11,13 @@ CREATE TABLE IF NOT EXISTS Labels ( FOREIGN KEY (account_id) REFERENCES Accounts (id) ); -- ! +CREATE TABLE IF NOT EXISTS LabelsInMessages ( + id INTEGER AUTO_INCREMENT PRIMARY KEY, + message_custom_id TEXT NOT NULL, + label_custom_id TEXT NOT NULL, + account_id INTEGER NOT NULL, + + FOREIGN KEY (account_id) REFERENCES Accounts (id) +); +-- ! UPDATE Information SET inf_value = '8' WHERE inf_key = 'schema_version'; \ No newline at end of file diff --git a/resources/sql/db_update_sqlite_7_8.sql b/resources/sql/db_update_sqlite_7_8.sql index 3ef1aa0bb..25da9dfcb 100755 --- a/resources/sql/db_update_sqlite_7_8.sql +++ b/resources/sql/db_update_sqlite_7_8.sql @@ -11,4 +11,15 @@ CREATE TABLE IF NOT EXISTS Labels ( FOREIGN KEY (account_id) REFERENCES Accounts (id) ); -- ! +CREATE TABLE IF NOT EXISTS LabelsInMessages ( + id INTEGER PRIMARY KEY, + message_custom_id TEXT NOT NULL, + label_custom_id TEXT NOT NULL, + account_id INTEGER NOT NULL, + + FOREIGN KEY (message_custom_id) REFERENCES Messages (custom_id), + FOREIGN KEY (label_custom_id) REFERENCES Labels (custom_id), + FOREIGN KEY (account_id) REFERENCES Accounts (id) +); +-- ! UPDATE Information SET inf_value = '8' WHERE inf_key = 'schema_version'; \ No newline at end of file