From 8b76960c1b265b26801b5c7791db6c3e4f40bfc3 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?C=C3=A9lestin=20Matte?= Date: Mon, 18 Oct 2021 18:04:37 +0200 Subject: [PATCH] Fix database install procedure: remove redundant tables in schema.sql Django's model and schema.sql both contain tables that are necessary for the execution of the application, but are mutually exclusive. This is due to some fields in the "messages" table that cannot be defined in django, and definition of tables in schema.sql that are already created by django. --- loader/sql/schema.sql | 43 ++++--------------------------------------- 1 file changed, 4 insertions(+), 39 deletions(-) diff --git a/loader/sql/schema.sql b/loader/sql/schema.sql index d9b5d5f..a86c6a9 100644 --- a/loader/sql/schema.sql +++ b/loader/sql/schema.sql @@ -2,23 +2,10 @@ BEGIN; -CREATE TABLE messages ( - id SERIAL NOT NULL PRIMARY KEY, - parentid int REFERENCES messages, - threadid int NOT NULL, - _from text NOT NULL, - _to text NOT NULL, - cc text NOT NULL, - subject text NOT NULL, - date timestamptz NOT NULL, - loaddate timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP, - has_attachment boolean NOT NULL, - hiddenstatus int NULL, - messageid text NOT NULL, - bodytxt text NOT NULL, - rawtxt bytea NOT NULL, - fti tsvector NOT NULL -); +ALTER TABLE messages + ADD COLUMN rawtxt bytea NOT NULL, + ADD COLUMN fti tsvector NOT NULL; + CREATE INDEX idx_messages_threadid ON messages(threadid); CREATE UNIQUE INDEX idx_messages_msgid ON messages(messageid); CREATE INDEX idx_messages_date ON messages(date); @@ -42,21 +29,6 @@ CREATE TABLE unresolved_messages( CREATE UNIQUE INDEX idx_unresolved_msgid_message ON unresolved_messages(msgid, message); -CREATE TABLE listgroups( - groupid int NOT NULL PRIMARY KEY, - groupname text NOT NULL UNIQUE, - sortkey int NOT NULL -); - -CREATE TABLE lists( - listid int NOT NULL PRIMARY KEY, - listname text NOT NULL UNIQUE, - shortdesc text NOT NULL, - description text NOT NULL, - active boolean NOT NULL, - groupid int NOT NULL REFERENCES listgroups(groupid) -); - CREATE TABLE list_months( listid int NOT NULL REFERENCES lists(listid), year int NOT NULL, @@ -71,13 +43,6 @@ CREATE TABLE list_threads( ); CREATE INDEX list_threads_listid_idx ON list_threads(listid); -CREATE TABLE attachments( - id serial not null primary key, - message int not null references messages(id), - filename text not null, - contenttype text not null, - attachment bytea not null -); CREATE INDEX idx_attachments_msg ON attachments(message); CREATE TABLE apiclients( -- 2.33.1