about summary refs log tree commit diff
path: root/migrations
diff options
context:
space:
mode:
Diffstat (limited to 'migrations')
-rw-r--r--migrations/.gitkeep0
-rw-r--r--migrations/00000000000000_diesel_initial_setup/down.sql6
-rw-r--r--migrations/00000000000000_diesel_initial_setup/up.sql36
-rw-r--r--migrations/2018-04-08-133240_create_posts/down.sql2
-rw-r--r--migrations/2018-04-08-133240_create_posts/up.sql13
-rw-r--r--migrations/2018-04-08-161017_joinable_posts/down.sql1
-rw-r--r--migrations/2018-04-08-161017_joinable_posts/up.sql1
-rw-r--r--migrations/2018-04-08-172739_default_posted/down.sql2
-rw-r--r--migrations/2018-04-08-172739_default_posted/up.sql2
-rw-r--r--migrations/2018-04-08-182319_add_authors/down.sql5
-rw-r--r--migrations/2018-04-08-182319_add_authors/up.sql10
-rw-r--r--migrations/2018-04-14-140818_posts_only_in_posts/down.sql1
-rw-r--r--migrations/2018-04-14-140818_posts_only_in_posts/up.sql6
-rw-r--r--migrations/2018-04-14-153202_add_stickies_improve_index/down.sql2
-rw-r--r--migrations/2018-04-14-153202_add_stickies_improve_index/up.sql21
-rw-r--r--migrations/2018-04-14-170750_search-index/down.sql2
-rw-r--r--migrations/2018-04-14-170750_search-index/up.sql21
-rw-r--r--migrations/2018-05-01-141548_add-users/down.sql63
-rw-r--r--migrations/2018-05-01-141548_add-users/up.sql83
-rw-r--r--migrations/2018-05-01-183232_simplified-post-view/down.sql1
-rw-r--r--migrations/2018-05-01-183232_simplified-post-view/up.sql11
-rw-r--r--migrations/2018-05-25-160648_add_closed_column/down.sql1
-rw-r--r--migrations/2018-05-25-160648_add_closed_column/up.sql1
-rw-r--r--migrations/2018-05-25-161939_add_closed_to_index/down.sql30
-rw-r--r--migrations/2018-05-25-161939_add_closed_to_index/up.sql35
25 files changed, 0 insertions, 356 deletions
diff --git a/migrations/.gitkeep b/migrations/.gitkeep
deleted file mode 100644
index e69de29bb2..0000000000
--- a/migrations/.gitkeep
+++ /dev/null
diff --git a/migrations/00000000000000_diesel_initial_setup/down.sql b/migrations/00000000000000_diesel_initial_setup/down.sql
deleted file mode 100644
index a9f5260911..0000000000
--- a/migrations/00000000000000_diesel_initial_setup/down.sql
+++ /dev/null
@@ -1,6 +0,0 @@
--- This file was automatically created by Diesel to setup helper functions
--- and other internal bookkeeping. This file is safe to edit, any future
--- changes will be added to existing projects as new migrations.
-
-DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass);
-DROP FUNCTION IF EXISTS diesel_set_updated_at();
diff --git a/migrations/00000000000000_diesel_initial_setup/up.sql b/migrations/00000000000000_diesel_initial_setup/up.sql
deleted file mode 100644
index d68895b1a7..0000000000
--- a/migrations/00000000000000_diesel_initial_setup/up.sql
+++ /dev/null
@@ -1,36 +0,0 @@
--- This file was automatically created by Diesel to setup helper functions
--- and other internal bookkeeping. This file is safe to edit, any future
--- changes will be added to existing projects as new migrations.
-
-
-
-
--- Sets up a trigger for the given table to automatically set a column called
--- `updated_at` whenever the row is modified (unless `updated_at` was included
--- in the modified columns)
---
--- # Example
---
--- ```sql
--- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW());
---
--- SELECT diesel_manage_updated_at('users');
--- ```
-CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$
-BEGIN
-    EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s
-                    FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);
-END;
-$$ LANGUAGE plpgsql;
-
-CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$
-BEGIN
-    IF (
-        NEW IS DISTINCT FROM OLD AND
-        NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at
-    ) THEN
-        NEW.updated_at := current_timestamp;
-    END IF;
-    RETURN NEW;
-END;
-$$ LANGUAGE plpgsql;
diff --git a/migrations/2018-04-08-133240_create_posts/down.sql b/migrations/2018-04-08-133240_create_posts/down.sql
deleted file mode 100644
index 8ebcef8e13..0000000000
--- a/migrations/2018-04-08-133240_create_posts/down.sql
+++ /dev/null
@@ -1,2 +0,0 @@
-DROP TABLE posts;
-DROP TABLE threads;
diff --git a/migrations/2018-04-08-133240_create_posts/up.sql b/migrations/2018-04-08-133240_create_posts/up.sql
deleted file mode 100644
index 7cf601fa2c..0000000000
--- a/migrations/2018-04-08-133240_create_posts/up.sql
+++ /dev/null
@@ -1,13 +0,0 @@
-CREATE TABLE threads (
-  id SERIAL PRIMARY KEY,
-  title VARCHAR NOT NULL,
-  body TEXT NOT NULL,
-  posted TIMESTAMPTZ NOT NULL
-);
-
-CREATE TABLE posts (
-  id SERIAL PRIMARY KEY,
-  thread SERIAL REFERENCES threads (id),
-  body TEXT NOT NULL,
-  posted TIMESTAMPTZ NOT NULL
-);
diff --git a/migrations/2018-04-08-161017_joinable_posts/down.sql b/migrations/2018-04-08-161017_joinable_posts/down.sql
deleted file mode 100644
index cc7874b410..0000000000
--- a/migrations/2018-04-08-161017_joinable_posts/down.sql
+++ /dev/null
@@ -1 +0,0 @@
-ALTER TABLE posts RENAME COLUMN thread_id TO thread;
diff --git a/migrations/2018-04-08-161017_joinable_posts/up.sql b/migrations/2018-04-08-161017_joinable_posts/up.sql
deleted file mode 100644
index 9713de6cfc..0000000000
--- a/migrations/2018-04-08-161017_joinable_posts/up.sql
+++ /dev/null
@@ -1 +0,0 @@
-ALTER TABLE posts RENAME COLUMN thread TO thread_id;
diff --git a/migrations/2018-04-08-172739_default_posted/down.sql b/migrations/2018-04-08-172739_default_posted/down.sql
deleted file mode 100644
index 64dc07e066..0000000000
--- a/migrations/2018-04-08-172739_default_posted/down.sql
+++ /dev/null
@@ -1,2 +0,0 @@
-ALTER TABLE threads ALTER COLUMN posted DROP DEFAULT;
-ALTER TABLE posts ALTER COLUMN posted DROP DEFAULT;
diff --git a/migrations/2018-04-08-172739_default_posted/up.sql b/migrations/2018-04-08-172739_default_posted/up.sql
deleted file mode 100644
index afca8181cc..0000000000
--- a/migrations/2018-04-08-172739_default_posted/up.sql
+++ /dev/null
@@ -1,2 +0,0 @@
-ALTER TABLE threads ALTER COLUMN posted SET DEFAULT (NOW() AT TIME ZONE 'UTC');
-ALTER TABLE posts ALTER COLUMN posted SET DEFAULT (NOW() AT TIME ZONE 'UTC');
diff --git a/migrations/2018-04-08-182319_add_authors/down.sql b/migrations/2018-04-08-182319_add_authors/down.sql
deleted file mode 100644
index 8ad8179080..0000000000
--- a/migrations/2018-04-08-182319_add_authors/down.sql
+++ /dev/null
@@ -1,5 +0,0 @@
-ALTER TABLE threads DROP COLUMN author_name;
-ALTER TABLE threads DROP COLUMN author_email;
-
-ALTER TABLE posts DROP COLUMN author_name;
-ALTER TABLE posts DROP COLUMN author_email;
diff --git a/migrations/2018-04-08-182319_add_authors/up.sql b/migrations/2018-04-08-182319_add_authors/up.sql
deleted file mode 100644
index ad5beb9f67..0000000000
--- a/migrations/2018-04-08-182319_add_authors/up.sql
+++ /dev/null
@@ -1,10 +0,0 @@
--- This migration adds an 'author' column to the thread & post table.
--- Authors don't currently exist as independent objects in the
--- database as most user management is simply delegated to the OIDC
--- provider.
-
-ALTER TABLE threads ADD COLUMN author_name VARCHAR NOT NULL DEFAULT 'anonymous';
-ALTER TABLE threads ADD COLUMN author_email VARCHAR NOT NULL DEFAULT 'unknown@example.org';
-
-ALTER TABLE posts ADD COLUMN author_name VARCHAR NOT NULL DEFAULT 'anonymous';
-ALTER TABLE posts ADD COLUMN author_email VARCHAR NOT NULL DEFAULT 'unknown@example.org';
diff --git a/migrations/2018-04-14-140818_posts_only_in_posts/down.sql b/migrations/2018-04-14-140818_posts_only_in_posts/down.sql
deleted file mode 100644
index bb6528f33d..0000000000
--- a/migrations/2018-04-14-140818_posts_only_in_posts/down.sql
+++ /dev/null
@@ -1 +0,0 @@
-ALTER TABLE threads ADD COLUMN body TEXT NOT NULL DEFAULT '';
diff --git a/migrations/2018-04-14-140818_posts_only_in_posts/up.sql b/migrations/2018-04-14-140818_posts_only_in_posts/up.sql
deleted file mode 100644
index 07ff9a1196..0000000000
--- a/migrations/2018-04-14-140818_posts_only_in_posts/up.sql
+++ /dev/null
@@ -1,6 +0,0 @@
--- Instead of storing the thread OP in the thread table, this will
--- make it a post as well.
--- At the time at which this migration was created no important data
--- existed in any converse instances, so data is not moved.
-
-ALTER TABLE threads DROP COLUMN body;
diff --git a/migrations/2018-04-14-153202_add_stickies_improve_index/down.sql b/migrations/2018-04-14-153202_add_stickies_improve_index/down.sql
deleted file mode 100644
index a67ada3d4a..0000000000
--- a/migrations/2018-04-14-153202_add_stickies_improve_index/down.sql
+++ /dev/null
@@ -1,2 +0,0 @@
-DROP VIEW thread_index;
-ALTER TABLE threads DROP COLUMN sticky;
diff --git a/migrations/2018-04-14-153202_add_stickies_improve_index/up.sql b/migrations/2018-04-14-153202_add_stickies_improve_index/up.sql
deleted file mode 100644
index 74a559e35d..0000000000
--- a/migrations/2018-04-14-153202_add_stickies_improve_index/up.sql
+++ /dev/null
@@ -1,21 +0,0 @@
--- Add support for stickies in threads
-ALTER TABLE threads ADD COLUMN sticky BOOLEAN NOT NULL DEFAULT FALSE;
-
--- CREATE a simple view that returns the list of threads ordered by
--- the last post that occured in the thread.
-CREATE VIEW thread_index AS
-  SELECT t.id AS thread_id,
-         t.title AS title,
-         t.author_name AS thread_author,
-         t.posted AS created,
-         t.sticky AS sticky,
-         p.id AS post_id,
-         p.author_name AS post_author,
-         p.posted AS posted
-    FROM threads t
-    JOIN (SELECT DISTINCT ON (thread_id)
-           id, thread_id, author_name, posted
-          FROM posts
-          ORDER BY thread_id, id DESC) AS p
-    ON t.id = p.thread_id
-    ORDER BY t.sticky DESC, p.id DESC;
diff --git a/migrations/2018-04-14-170750_search-index/down.sql b/migrations/2018-04-14-170750_search-index/down.sql
deleted file mode 100644
index c57e662902..0000000000
--- a/migrations/2018-04-14-170750_search-index/down.sql
+++ /dev/null
@@ -1,2 +0,0 @@
-DROP INDEX idx_fts_search;
-DROP MATERIALIZED VIEW search_index;
diff --git a/migrations/2018-04-14-170750_search-index/up.sql b/migrations/2018-04-14-170750_search-index/up.sql
deleted file mode 100644
index 6b7d90eca6..0000000000
--- a/migrations/2018-04-14-170750_search-index/up.sql
+++ /dev/null
@@ -1,21 +0,0 @@
--- Prepare a materialised view containing the tsvector data for all
--- threads and posts. This view is indexed using a GIN-index to enable
--- performant full-text searches.
---
--- For now the query language is hardcoded to be English.
-
-CREATE MATERIALIZED VIEW search_index AS
-  SELECT p.id AS post_id,
-         p.author_name AS author,
-         t.id AS thread_id,
-         t.title AS title,
-         p.body AS body,
-         setweight(to_tsvector('english', t.title), 'B') ||
-         setweight(to_tsvector('english', p.body), 'A') ||
-         setweight(to_tsvector('simple', t.author_name), 'C') ||
-         setweight(to_tsvector('simple', p.author_name), 'C') AS document
-    FROM posts p
-    JOIN threads t
-    ON t.id = p.thread_id;
-
-CREATE INDEX idx_fts_search ON search_index USING gin(document);
diff --git a/migrations/2018-05-01-141548_add-users/down.sql b/migrations/2018-05-01-141548_add-users/down.sql
deleted file mode 100644
index 61fd222e18..0000000000
--- a/migrations/2018-05-01-141548_add-users/down.sql
+++ /dev/null
@@ -1,63 +0,0 @@
--- First restore the old columns:
-ALTER TABLE threads ADD COLUMN author_name VARCHAR;
-ALTER TABLE threads ADD COLUMN author_email VARCHAR;
-ALTER TABLE posts ADD COLUMN author_name VARCHAR;
-ALTER TABLE posts ADD COLUMN author_email VARCHAR;
-
--- Then select the data back into them:
-UPDATE threads SET author_name = users.name,
-                   author_email = users.email
-  FROM users
-  WHERE threads.user_id = users.id;
-
-UPDATE posts SET author_name = users.name,
-                 author_email = users.email
-  FROM users
-  WHERE posts.user_id = users.id;
-
--- add the constraints back:
-ALTER TABLE threads ALTER COLUMN author_name SET NOT NULL;
-ALTER TABLE threads ALTER COLUMN author_email SET NOT NULL;
-ALTER TABLE posts ALTER COLUMN author_name SET NOT NULL;
-ALTER TABLE posts ALTER COLUMN author_email SET NOT NULL;
-
--- reset the index view:
-CREATE OR REPLACE VIEW thread_index AS
-  SELECT t.id AS thread_id,
-         t.title AS title,
-         t.author_name AS thread_author,
-         t.posted AS created,
-         t.sticky AS sticky,
-         p.id AS post_id,
-         p.author_name AS post_author,
-         p.posted AS posted
-    FROM threads t
-    JOIN (SELECT DISTINCT ON (thread_id)
-           id, thread_id, author_name, posted
-          FROM posts
-          ORDER BY thread_id, id DESC) AS p
-    ON t.id = p.thread_id
-    ORDER BY t.sticky DESC, p.id DESC;
-
--- reset the search view:
-DROP MATERIALIZED VIEW search_index;
-CREATE MATERIALIZED VIEW search_index AS
-  SELECT p.id AS post_id,
-         p.author_name AS author,
-         t.id AS thread_id,
-         t.title AS title,
-         p.body AS body,
-         setweight(to_tsvector('english', t.title), 'B') ||
-         setweight(to_tsvector('english', p.body), 'A') ||
-         setweight(to_tsvector('simple', t.author_name), 'C') ||
-         setweight(to_tsvector('simple', p.author_name), 'C') AS document
-    FROM posts p
-    JOIN threads t
-    ON t.id = p.thread_id;
-
-CREATE INDEX idx_fts_search ON search_index USING gin(document);
-
--- and drop the users table and columns:
-ALTER TABLE posts DROP COLUMN user_id;
-ALTER TABLE threads DROP COLUMN user_id;
-DROP TABLE users;
diff --git a/migrations/2018-05-01-141548_add-users/up.sql b/migrations/2018-05-01-141548_add-users/up.sql
deleted file mode 100644
index fcb7133e8e..0000000000
--- a/migrations/2018-05-01-141548_add-users/up.sql
+++ /dev/null
@@ -1,83 +0,0 @@
--- This query creates a users table and migrates the existing user
--- information (from the posts table) into it.
-
-CREATE TABLE users (
-  id SERIAL PRIMARY KEY,
-  email VARCHAR NOT NULL UNIQUE,
-  name VARCHAR NOT NULL,
-  admin BOOLEAN NOT NULL DEFAULT false
-);
-
--- Insert the 'anonymous' user explicitly:
-INSERT INTO users (name, email)
-  VALUES ('Anonymous', 'anonymous@nothing.org');
-
-INSERT INTO users (id, email, name)
-  SELECT nextval('users_id_seq'),
-         author_email AS email,
-         author_name AS name
-  FROM posts
-  WHERE author_email != 'anonymous@nothing.org'
-  GROUP BY name, email;
-
--- Create the 'user_id' column in the relevant tables (initially
--- without a not-null constraint) and populate it with the data
--- selected above:
-ALTER TABLE posts ADD COLUMN user_id INTEGER REFERENCES users (id);
-UPDATE posts SET user_id = users.id
-  FROM users
-  WHERE users.email = posts.author_email;
-
-ALTER TABLE threads ADD COLUMN user_id INTEGER REFERENCES users (id);
-UPDATE threads SET user_id = users.id
-  FROM users
-  WHERE users.email = threads.author_email;
-
--- Add the constraints:
-ALTER TABLE posts ALTER COLUMN user_id SET NOT NULL;
-ALTER TABLE threads ALTER COLUMN user_id SET NOT NULL;
-
--- Update the index view:
-CREATE OR REPLACE VIEW thread_index AS
-  SELECT t.id AS thread_id,
-         t.title AS title,
-         ta.name AS thread_author,
-         t.posted AS created,
-         t.sticky AS sticky,
-         p.id AS post_id,
-         pa.name AS post_author,
-         p.posted AS posted
-    FROM threads t
-    JOIN (SELECT DISTINCT ON (thread_id)
-           id, thread_id, user_id, posted
-          FROM posts
-          ORDER BY thread_id, id DESC) AS p
-    ON t.id = p.thread_id
-    JOIN users ta ON ta.id = t.user_id
-    JOIN users pa ON pa.id = p.user_id
-    ORDER BY t.sticky DESC, p.id DESC;
-
--- Update the search view:
-DROP MATERIALIZED VIEW search_index;
-CREATE MATERIALIZED VIEW search_index AS
-  SELECT p.id AS post_id,
-         pa.name AS author,
-         t.id AS thread_id,
-         t.title AS title,
-         p.body AS body,
-         setweight(to_tsvector('english', t.title), 'B') ||
-         setweight(to_tsvector('english', p.body), 'A') ||
-         setweight(to_tsvector('simple', ta.name), 'C') ||
-         setweight(to_tsvector('simple', pa.name), 'C') AS document
-    FROM posts p
-    JOIN threads t ON t.id = p.thread_id
-    JOIN users ta ON ta.id = t.user_id
-    JOIN users pa ON pa.id = p.user_id;
-
-CREATE INDEX idx_fts_search ON search_index USING gin(document);
-
--- And drop the old fields:
-ALTER TABLE posts DROP COLUMN author_name;
-ALTER TABLE posts DROP COLUMN author_email;
-ALTER TABLE threads DROP COLUMN author_name;
-ALTER TABLE threads DROP COLUMN author_email;
diff --git a/migrations/2018-05-01-183232_simplified-post-view/down.sql b/migrations/2018-05-01-183232_simplified-post-view/down.sql
deleted file mode 100644
index 0f14732f38..0000000000
--- a/migrations/2018-05-01-183232_simplified-post-view/down.sql
+++ /dev/null
@@ -1 +0,0 @@
-DROP VIEW simple_posts;
diff --git a/migrations/2018-05-01-183232_simplified-post-view/up.sql b/migrations/2018-05-01-183232_simplified-post-view/up.sql
deleted file mode 100644
index 280fef8700..0000000000
--- a/migrations/2018-05-01-183232_simplified-post-view/up.sql
+++ /dev/null
@@ -1,11 +0,0 @@
--- Creates a view for listing posts akin to the post table before
--- splitting out users. This exists to avoid having to do joining
--- logic and such inside of the application.
-
-CREATE VIEW simple_posts AS
-  SELECT p.id AS id,
-         thread_id, body, posted, user_id,
-         users.name AS author_name,
-         users.email AS author_email
-  FROM posts p
-  JOIN users ON users.id = p.user_id;
diff --git a/migrations/2018-05-25-160648_add_closed_column/down.sql b/migrations/2018-05-25-160648_add_closed_column/down.sql
deleted file mode 100644
index fb2a98c0af..0000000000
--- a/migrations/2018-05-25-160648_add_closed_column/down.sql
+++ /dev/null
@@ -1 +0,0 @@
-ALTER TABLE threads DROP COLUMN closed;
diff --git a/migrations/2018-05-25-160648_add_closed_column/up.sql b/migrations/2018-05-25-160648_add_closed_column/up.sql
deleted file mode 100644
index d7d4c44da2..0000000000
--- a/migrations/2018-05-25-160648_add_closed_column/up.sql
+++ /dev/null
@@ -1 +0,0 @@
-ALTER TABLE threads ADD COLUMN closed BOOLEAN NOT NULL DEFAULT false;
diff --git a/migrations/2018-05-25-161939_add_closed_to_index/down.sql b/migrations/2018-05-25-161939_add_closed_to_index/down.sql
deleted file mode 100644
index 1063fdc882..0000000000
--- a/migrations/2018-05-25-161939_add_closed_to_index/down.sql
+++ /dev/null
@@ -1,30 +0,0 @@
--- Update the index view:
-DROP VIEW thread_index;
-CREATE VIEW thread_index AS
-  SELECT t.id AS thread_id,
-         t.title AS title,
-         ta.name AS thread_author,
-         t.posted AS created,
-         t.sticky AS sticky,
-         p.id AS post_id,
-         pa.name AS post_author,
-         p.posted AS posted
-    FROM threads t
-    JOIN (SELECT DISTINCT ON (thread_id)
-           id, thread_id, user_id, posted
-          FROM posts
-          ORDER BY thread_id, id DESC) AS p
-    ON t.id = p.thread_id
-    JOIN users ta ON ta.id = t.user_id
-    JOIN users pa ON pa.id = p.user_id
-    ORDER BY t.sticky DESC, p.id DESC;
-
--- Update the post view:
-DROP VIEW simple_posts;
-CREATE VIEW simple_posts AS
-  SELECT p.id AS id,
-         thread_id, body, posted, user_id,
-         users.name AS author_name,
-         users.email AS author_email
-  FROM posts p
-  JOIN users ON users.id = p.user_id;
diff --git a/migrations/2018-05-25-161939_add_closed_to_index/up.sql b/migrations/2018-05-25-161939_add_closed_to_index/up.sql
deleted file mode 100644
index 87580a2f3f..0000000000
--- a/migrations/2018-05-25-161939_add_closed_to_index/up.sql
+++ /dev/null
@@ -1,35 +0,0 @@
--- Update the index view:
-DROP VIEW thread_index;
-CREATE VIEW thread_index AS
-  SELECT t.id AS thread_id,
-         t.title AS title,
-         ta.name AS thread_author,
-         t.posted AS created,
-         t.sticky AS sticky,
-         t.closed AS closed,
-         p.id AS post_id,
-         pa.name AS post_author,
-         p.posted AS posted
-    FROM threads t
-    JOIN (SELECT DISTINCT ON (thread_id)
-           id, thread_id, user_id, posted
-          FROM posts
-          ORDER BY thread_id, id DESC) AS p
-    ON t.id = p.thread_id
-    JOIN users ta ON ta.id = t.user_id
-    JOIN users pa ON pa.id = p.user_id
-    ORDER BY t.sticky DESC, p.id DESC;
-
--- Update post view:
-DROP VIEW simple_posts;
-CREATE VIEW simple_posts AS
-  SELECT p.id AS id,
-         thread_id, body,
-         p.posted AS posted,
-         p.user_id AS user_id,
-         threads.closed AS closed,
-         users.name AS author_name,
-         users.email AS author_email
-  FROM posts p
-  JOIN users ON users.id = p.user_id
-  JOIN threads ON threads.id = p.thread_id;