From 6bcc4f0ab09a36fc4750bcdd76110e5af895c6ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Wed, 22 May 2019 14:29:52 +0100 Subject: [PATCH] add custom_domain (default to NULL) to schema --- .../down.sql | 2 + .../up.sql | 2 + .../down.sql | 56 +++++++ .../up.sql | 57 +++++++ plume-models/src/blogs.rs | 3 + plume-models/src/schema.rs | 153 +++++++++--------- 6 files changed, 197 insertions(+), 76 deletions(-) create mode 100644 migrations/postgres/2019-05-22-124143_add_custom_domains/down.sql create mode 100644 migrations/postgres/2019-05-22-124143_add_custom_domains/up.sql create mode 100644 migrations/sqlite/2019-05-22-124153_add_custom_domains/down.sql create mode 100644 migrations/sqlite/2019-05-22-124153_add_custom_domains/up.sql diff --git a/migrations/postgres/2019-05-22-124143_add_custom_domains/down.sql b/migrations/postgres/2019-05-22-124143_add_custom_domains/down.sql new file mode 100644 index 00000000..7f181714 --- /dev/null +++ b/migrations/postgres/2019-05-22-124143_add_custom_domains/down.sql @@ -0,0 +1,2 @@ +-- undo the adding of custom_domain column to blogs table. +ALTER TABLE blogs DROP COLUMN custom_domain; diff --git a/migrations/postgres/2019-05-22-124143_add_custom_domains/up.sql b/migrations/postgres/2019-05-22-124143_add_custom_domains/up.sql new file mode 100644 index 00000000..d00f5a29 --- /dev/null +++ b/migrations/postgres/2019-05-22-124143_add_custom_domains/up.sql @@ -0,0 +1,2 @@ +--- Adding custom domain to Blog as an optional field +ALTER TABLE blogs ADD COLUMN custom_domain VARCHAR DEFAULT NULL UNIQUE; diff --git a/migrations/sqlite/2019-05-22-124153_add_custom_domains/down.sql b/migrations/sqlite/2019-05-22-124153_add_custom_domains/down.sql new file mode 100644 index 00000000..ed5d9231 --- /dev/null +++ b/migrations/sqlite/2019-05-22-124153_add_custom_domains/down.sql @@ -0,0 +1,56 @@ +-- undo the adding of "custom_domain" to blogs +CREATE TABLE IF NOT EXISTS "blogs_drop_custom_domain" ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + actor_id VARCHAR NOT NULL, + title VARCHAR NOT NULL, + summary TEXT NOT NULL DEFAULT '', + outbox_url VARCHAR NOT NULL UNIQUE, + inbox_url VARCHAR NOT NULL UNIQUE, + instance_id INTEGER REFERENCES instances(id) ON DELETE CASCADE NOT NULL, + creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + ap_url text not null default '' UNIQUE, + private_key TEXT, + public_key TEXT NOT NULL DEFAULT '', + fqn TEXT NOT NULL DEFAULT '', + summary_html TEXT NOT NULL DEFAULT '', + icon_id INTEGER REFERENCES medias(id) ON DELETE SET NULL DEFAULT NULL, + banner_id INTEGER REFERENCES medias(id) ON DELETE SET NULL DEFAULT NULL, + CONSTRAINT blog_unique UNIQUE (actor_id, instance_id) +); + +INSERT INTO blogs_drop_custom_domain ( + id, + actor_id, + title, + summary, + outbox_url, + inbox_url, + instance_id, + creation_date, + ap_url, + private_key, + public_key, + fqn, + summary_html, + icon_id, + banner_id +) SELECT + id, + actor_id, + title, + summary, + outbox_url, + inbox_url, + instance_id, + creation_date, + ap_url, + private_key, + public_key, + fqn, + summary_html, + icon_id, + banner_id +FROM blogs; + +DROP TABLE blogs; +ALTER TABLE "blogs_drop_custom_domain" RENAME to blogs; diff --git a/migrations/sqlite/2019-05-22-124153_add_custom_domains/up.sql b/migrations/sqlite/2019-05-22-124153_add_custom_domains/up.sql new file mode 100644 index 00000000..1cdffa7c --- /dev/null +++ b/migrations/sqlite/2019-05-22-124153_add_custom_domains/up.sql @@ -0,0 +1,57 @@ +-- add custom_domain to blogs +CREATE TABLE IF NOT EXISTS "blogs_add_custom_domain" ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + actor_id VARCHAR NOT NULL, + title VARCHAR NOT NULL, + summary TEXT NOT NULL DEFAULT '', + outbox_url VARCHAR NOT NULL UNIQUE, + inbox_url VARCHAR NOT NULL UNIQUE, + instance_id INTEGER REFERENCES instances(id) ON DELETE CASCADE NOT NULL, + creation_date DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + ap_url text not null default '' UNIQUE, + private_key TEXT, + public_key TEXT NOT NULL DEFAULT '', + fqn TEXT NOT NULL DEFAULT '', + summary_html TEXT NOT NULL DEFAULT '', + icon_id INTEGER REFERENCES medias(id) ON DELETE SET NULL DEFAULT NULL, + banner_id INTEGER REFERENCES medias(id) ON DELETE SET NULL DEFAULT NULL, + custom_domain text default NULL UNIQUE, + CONSTRAINT blog_unique UNIQUE (actor_id, instance_id) +); + +INSERT INTO blogs_add_custom_domain ( + id, + actor_id, + title, + summary, + outbox_url, + inbox_url, + instance_id, + creation_date, + ap_url, + private_key, + public_key, + fqn, + summary_html, + icon_id, + banner_id +) SELECT + id, + actor_id, + title, + summary, + outbox_url, + inbox_url, + instance_id, + creation_date, + ap_url, + private_key, + public_key, + fqn, + summary_html, + icon_id, + banner_id +FROM blogs; + +DROP TABLE blogs; +ALTER TABLE "blogs_add_custom_domain" RENAME to blogs; diff --git a/plume-models/src/blogs.rs b/plume-models/src/blogs.rs index 8c55f402..7fd91aa3 100644 --- a/plume-models/src/blogs.rs +++ b/plume-models/src/blogs.rs @@ -44,6 +44,7 @@ pub struct Blog { pub summary_html: SafeString, pub icon_id: Option, pub banner_id: Option, + pub custom_domain: Option, } #[derive(Default, Insertable)] @@ -61,6 +62,7 @@ pub struct NewBlog { pub summary_html: SafeString, pub icon_id: Option, pub banner_id: Option, + pub custom_domain: Option, } const BLOG_PREFIX: &str = "~"; @@ -392,6 +394,7 @@ impl FromId for Blog { .summary_string() .unwrap_or_default(), ), + custom_domain: None, }, ) } diff --git a/plume-models/src/schema.rs b/plume-models/src/schema.rs index f2cc833c..01570bac 100644 --- a/plume-models/src/schema.rs +++ b/plume-models/src/schema.rs @@ -1,17 +1,17 @@ table! { api_tokens (id) { - id -> Int4, + id -> Integer, creation_date -> Timestamp, value -> Text, scopes -> Text, - app_id -> Int4, - user_id -> Int4, + app_id -> Integer, + user_id -> Integer, } } table! { apps (id) { - id -> Int4, + id -> Integer, name -> Text, client_id -> Text, client_secret -> Text, @@ -23,70 +23,71 @@ table! { table! { blog_authors (id) { - id -> Int4, - blog_id -> Int4, - author_id -> Int4, + id -> Integer, + blog_id -> Integer, + author_id -> Integer, is_owner -> Bool, } } table! { blogs (id) { - id -> Int4, - actor_id -> Varchar, - title -> Varchar, + id -> Integer, + actor_id -> Text, + title -> Text, summary -> Text, - outbox_url -> Varchar, - inbox_url -> Varchar, - instance_id -> Int4, + outbox_url -> Text, + inbox_url -> Text, + instance_id -> Integer, creation_date -> Timestamp, ap_url -> Text, private_key -> Nullable, public_key -> Text, fqn -> Text, summary_html -> Text, - icon_id -> Nullable, - banner_id -> Nullable, + icon_id -> Nullable, + banner_id -> Nullable, + custom_domain -> Nullable, + } +} + +table! { + comment_seers (id) { + id -> Integer, + comment_id -> Integer, + user_id -> Integer, } } table! { comments (id) { - id -> Int4, + id -> Integer, content -> Text, - in_response_to_id -> Nullable, - post_id -> Int4, - author_id -> Int4, + in_response_to_id -> Nullable, + post_id -> Integer, + author_id -> Integer, creation_date -> Timestamp, - ap_url -> Nullable, + ap_url -> Nullable, sensitive -> Bool, spoiler_text -> Text, public_visibility -> Bool, } } -table! { - comment_seers (id) { - id -> Int4, - comment_id -> Int4, - user_id -> Int4, - } -} - table! { follows (id) { - id -> Int4, - follower_id -> Int4, - following_id -> Int4, + id -> Integer, + follower_id -> Integer, + following_id -> Integer, ap_url -> Text, } } table! { instances (id) { - id -> Int4, - public_domain -> Varchar, - name -> Varchar, + id -> Integer, + public_domain -> Text, + name -> Text, local -> Bool, blocked -> Bool, creation_date -> Timestamp, @@ -94,50 +95,50 @@ table! { short_description -> Text, long_description -> Text, default_license -> Text, - long_description_html -> Varchar, - short_description_html -> Varchar, + long_description_html -> Text, + short_description_html -> Text, } } table! { likes (id) { - id -> Int4, - user_id -> Int4, - post_id -> Int4, + id -> Integer, + user_id -> Integer, + post_id -> Integer, creation_date -> Timestamp, - ap_url -> Varchar, + ap_url -> Text, } } table! { medias (id) { - id -> Int4, + id -> Integer, file_path -> Text, alt_text -> Text, is_remote -> Bool, remote_url -> Nullable, sensitive -> Bool, content_warning -> Nullable, - owner_id -> Int4, + owner_id -> Integer, } } table! { mentions (id) { - id -> Int4, - mentioned_id -> Int4, - post_id -> Nullable, - comment_id -> Nullable, + id -> Integer, + mentioned_id -> Integer, + post_id -> Nullable, + comment_id -> Nullable, } } table! { notifications (id) { - id -> Int4, - user_id -> Int4, + id -> Integer, + user_id -> Integer, creation_date -> Timestamp, - kind -> Varchar, - object_id -> Int4, + kind -> Text, + object_id -> Integer, } } @@ -152,67 +153,67 @@ table! { table! { post_authors (id) { - id -> Int4, - post_id -> Int4, - author_id -> Int4, + id -> Integer, + post_id -> Integer, + author_id -> Integer, } } table! { posts (id) { - id -> Int4, - blog_id -> Int4, - slug -> Varchar, - title -> Varchar, + id -> Integer, + blog_id -> Integer, + slug -> Text, + title -> Text, content -> Text, published -> Bool, - license -> Varchar, + license -> Text, creation_date -> Timestamp, - ap_url -> Varchar, + ap_url -> Text, subtitle -> Text, source -> Text, - cover_id -> Nullable, + cover_id -> Nullable, } } table! { reshares (id) { - id -> Int4, - user_id -> Int4, - post_id -> Int4, - ap_url -> Varchar, + id -> Integer, + user_id -> Integer, + post_id -> Integer, + ap_url -> Text, creation_date -> Timestamp, } } table! { tags (id) { - id -> Int4, + id -> Integer, tag -> Text, is_hashtag -> Bool, - post_id -> Int4, + post_id -> Integer, } } table! { users (id) { - id -> Int4, - username -> Varchar, - display_name -> Varchar, - outbox_url -> Varchar, - inbox_url -> Varchar, + id -> Integer, + username -> Text, + display_name -> Text, + outbox_url -> Text, + inbox_url -> Text, is_admin -> Bool, summary -> Text, email -> Nullable, hashed_password -> Nullable, - instance_id -> Int4, + instance_id -> Integer, creation_date -> Timestamp, ap_url -> Text, private_key -> Nullable, public_key -> Text, - shared_inbox_url -> Nullable, - followers_endpoint -> Varchar, - avatar_id -> Nullable, + shared_inbox_url -> Nullable, + followers_endpoint -> Text, + avatar_id -> Nullable, last_fetched_date -> Timestamp, fqn -> Text, summary_html -> Text, @@ -248,8 +249,8 @@ allow_tables_to_appear_in_same_query!( apps, blog_authors, blogs, - comments, comment_seers, + comments, follows, instances, likes,