diff options
author | multiple creatures <dev@multiple-creature.party> | 2019-12-11 22:00:22 -0600 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2019-12-11 22:00:22 -0600 |
commit | dae7cda4abe135b3bb5fe9cfb3380721a2feb03e (patch) | |
tree | 4eda3ccfee17cb36a461d31cf74d266d80f6ebae /db | |
parent | 9a435494c2efdd2ca8fc7f5fa3dbb81bf88633a1 (diff) |
move sharekeys & import metadata to own tables
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20191211235208_create_normalized_statuses.rb | 2 | ||||
-rw-r--r-- | db/migrate/20191212022020_create_sharekeys.rb | 19 | ||||
-rw-r--r-- | db/migrate/20191212022653_create_imported_statuses.rb | 21 | ||||
-rw-r--r-- | db/schema.rb | 21 |
4 files changed, 57 insertions, 6 deletions
diff --git a/db/migrate/20191211235208_create_normalized_statuses.rb b/db/migrate/20191211235208_create_normalized_statuses.rb index 9baaa3f62..d47c4feb4 100644 --- a/db/migrate/20191211235208_create_normalized_statuses.rb +++ b/db/migrate/20191211235208_create_normalized_statuses.rb @@ -1,7 +1,7 @@ class CreateNormalizedStatuses < ActiveRecord::Migration[5.2] def up create_table :normalized_statuses do |t| - t.references :status, foreign_key: true + t.references :status, foreign_key: true, index: {unique: true} t.text :text end diff --git a/db/migrate/20191212022020_create_sharekeys.rb b/db/migrate/20191212022020_create_sharekeys.rb new file mode 100644 index 000000000..c0027babe --- /dev/null +++ b/db/migrate/20191212022020_create_sharekeys.rb @@ -0,0 +1,19 @@ +class CreateSharekeys < ActiveRecord::Migration[5.2] + def up + create_table :sharekeys do |t| + t.references :status, foreign_key: true, index: {unique: true} + t.string :key + end + + safety_assured do + execute 'INSERT INTO sharekeys (status_id, key) SELECT id, sharekey FROM statuses WHERE local AND sharekey IS NOT NULL' + remove_column :statuses, :sharekey + end + end + + def down + add_column :statuses, :sharekey, :string + execute 'UPDATE statuses SET sharekey = s.key FROM (SELECT status_id, key FROM sharekeys) AS s WHERE statuses.id = s.id' + drop_table :sharekeys + end +end diff --git a/db/migrate/20191212022653_create_imported_statuses.rb b/db/migrate/20191212022653_create_imported_statuses.rb new file mode 100644 index 000000000..3d7a9c99d --- /dev/null +++ b/db/migrate/20191212022653_create_imported_statuses.rb @@ -0,0 +1,21 @@ +class CreateImportedStatuses < ActiveRecord::Migration[5.2] + def up + create_table :imported_statuses do |t| + t.references :status, foreign_key: true, index: {unique: true} + t.string :origin, index: {unique: true} + end + + safety_assured { execute 'INSERT INTO imported_statuses (status_id, origin) SELECT id, origin FROM statuses WHERE imported' } + safety_assured do + remove_column :statuses, :imported + remove_column :statuses, :origin + end + end + + def down + add_column :statuses, :imported, :boolean + add_column :statuses, :origin, :string, index: { unique: true } + execute 'UPDATE statuses SET imported = true, origin = s.origin FROM (SELECT status_id, origin FROM imported_statuses) AS s WHERE statuses.id = s.id' + drop_table :imported_statuses + end +end diff --git a/db/schema.rb b/db/schema.rb index 96e9148ed..47b792a8b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_12_12_002705) do +ActiveRecord::Schema.define(version: 2019_12_12_022653) do # These are extensions that must be enabled in order to support this database enable_extension "pg_trgm" @@ -335,6 +335,13 @@ ActiveRecord::Schema.define(version: 2019_12_12_002705) do t.index ["user_id"], name: "index_identities_on_user_id" end + create_table "imported_statuses", force: :cascade do |t| + t.bigint "status_id" + t.string "origin" + t.index ["origin"], name: "index_imported_statuses_on_origin", unique: true + t.index ["status_id"], name: "index_imported_statuses_on_status_id", unique: true + end + create_table "imports", force: :cascade do |t| t.integer "type", null: false t.boolean "approved", default: false, null: false @@ -636,6 +643,12 @@ ActiveRecord::Schema.define(version: 2019_12_12_002705) do t.index ["thing_type", "thing_id", "var"], name: "index_settings_on_thing_type_and_thing_id_and_var", unique: true end + create_table "sharekeys", force: :cascade do |t| + t.bigint "status_id" + t.string "key" + t.index ["status_id"], name: "index_sharekeys_on_status_id", unique: true + end + create_table "site_uploads", force: :cascade do |t| t.string "var", default: "", null: false t.string "file_file_name" @@ -687,13 +700,10 @@ ActiveRecord::Schema.define(version: 2019_12_12_002705) do t.boolean "local_only" t.bigint "poll_id" t.boolean "curated", default: false, null: false - t.string "sharekey" t.boolean "network", default: false, null: false t.string "content_type" t.text "footer" t.boolean "edited" - t.boolean "imported" - t.string "origin" t.boolean "boostable" t.boolean "reject_replies" t.index ["account_id", "id", "visibility", "updated_at"], name: "index_statuses_20180106", order: { id: :desc } @@ -701,7 +711,6 @@ ActiveRecord::Schema.define(version: 2019_12_12_002705) do t.index ["in_reply_to_account_id"], name: "index_statuses_on_in_reply_to_account_id" t.index ["in_reply_to_id"], name: "index_statuses_on_in_reply_to_id" t.index ["network"], name: "index_statuses_on_network", where: "network" - t.index ["origin"], name: "index_statuses_on_origin", unique: true t.index ["reblog_of_id", "account_id"], name: "index_statuses_on_reblog_of_id_and_account_id" t.index ["uri"], name: "index_statuses_on_uri", unique: true end @@ -850,6 +859,7 @@ ActiveRecord::Schema.define(version: 2019_12_12_002705) do add_foreign_key "follows", "accounts", column: "target_account_id", name: "fk_745ca29eac", on_delete: :cascade add_foreign_key "follows", "accounts", name: "fk_32ed1b5560", on_delete: :cascade add_foreign_key "identities", "users", name: "fk_bea040f377", on_delete: :cascade + add_foreign_key "imported_statuses", "statuses" add_foreign_key "imports", "accounts", name: "fk_6db1b6e408", on_delete: :cascade add_foreign_key "invites", "users", on_delete: :cascade add_foreign_key "linked_users", "users", column: "target_user_id", on_delete: :cascade @@ -888,6 +898,7 @@ ActiveRecord::Schema.define(version: 2019_12_12_002705) do add_foreign_key "scheduled_statuses", "accounts", on_delete: :cascade add_foreign_key "session_activations", "oauth_access_tokens", column: "access_token_id", name: "fk_957e5bda89", on_delete: :cascade add_foreign_key "session_activations", "users", name: "fk_e5fda67334", on_delete: :cascade + add_foreign_key "sharekeys", "statuses" add_foreign_key "status_pins", "accounts", name: "fk_d4cb435b62", on_delete: :cascade add_foreign_key "status_pins", "statuses", on_delete: :cascade add_foreign_key "status_stats", "statuses", on_delete: :cascade |