FlakeId: chain alter statements
This commit is contained in:
parent
e67bd93d90
commit
9ba6e1fabe
1 changed files with 24 additions and 14 deletions
|
@ -25,17 +25,21 @@ def change do
|
||||||
execute "LOCK TABLE activities;"
|
execute "LOCK TABLE activities;"
|
||||||
execute "LOCK TABLE users;"
|
execute "LOCK TABLE users;"
|
||||||
|
|
||||||
execute "ALTER TABLE activities DROP CONSTRAINT activities_pkey CASCADE;"
|
execute """
|
||||||
execute "ALTER TABLE users DROP CONSTRAINT users_pkey CASCADE;"
|
ALTER TABLE activities
|
||||||
|
DROP CONSTRAINT activities_pkey CASCADE,
|
||||||
|
ALTER COLUMN id DROP default,
|
||||||
|
ALTER COLUMN id SET DATA TYPE uuid USING CAST( LPAD( TO_HEX(id), 32, '0' ) AS uuid),
|
||||||
|
ADD PRIMARY KEY (id);
|
||||||
|
"""
|
||||||
|
|
||||||
execute "ALTER TABLE activities ALTER COLUMN id DROP default;"
|
execute """
|
||||||
execute "ALTER TABLE users ALTER COLUMN id DROP default;"
|
ALTER TABLE users
|
||||||
|
DROP CONSTRAINT users_pkey CASCADE,
|
||||||
execute "ALTER TABLE activities ALTER COLUMN id SET DATA TYPE uuid USING CAST( LPAD( TO_HEX(id), 32, '0' ) AS uuid);"
|
ALTER COLUMN id DROP default,
|
||||||
execute "ALTER TABLE users ALTER COLUMN id SET DATA TYPE uuid USING CAST( LPAD( TO_HEX(id), 32, '0' ) AS uuid);"
|
ALTER COLUMN id SET DATA TYPE uuid USING CAST( LPAD( TO_HEX(id), 32, '0' ) AS uuid),
|
||||||
|
ADD PRIMARY KEY (id);
|
||||||
execute "ALTER TABLE activities ADD PRIMARY KEY (id);"
|
"""
|
||||||
execute "ALTER TABLE users ADD PRIMARY KEY (id);"
|
|
||||||
|
|
||||||
execute "UPDATE users SET info = jsonb_set(info, '{pinned_activities}', array_to_json(ARRAY(select jsonb_array_elements_text(info->'pinned_activities')))::jsonb);"
|
execute "UPDATE users SET info = jsonb_set(info, '{pinned_activities}', array_to_json(ARRAY(select jsonb_array_elements_text(info->'pinned_activities')))::jsonb);"
|
||||||
|
|
||||||
|
@ -52,12 +56,18 @@ def change do
|
||||||
# TABLE "push_subscriptions" CONSTRAINT "push_subscriptions_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
# TABLE "push_subscriptions" CONSTRAINT "push_subscriptions_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
|
||||||
# TABLE "websub_client_subscriptions" CONSTRAINT "websub_client_subscriptions_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id)
|
# TABLE "websub_client_subscriptions" CONSTRAINT "websub_client_subscriptions_user_id_fkey" FOREIGN KEY (user_id) REFERENCES users(id)
|
||||||
|
|
||||||
execute "ALTER TABLE notifications ALTER COLUMN activity_id SET DATA TYPE uuid USING CAST( LPAD( TO_HEX(activity_id), 32, '0' ) AS uuid);"
|
execute """
|
||||||
execute "ALTER TABLE notifications ADD CONSTRAINT notifications_activity_id_fkey FOREIGN KEY (activity_id) REFERENCES activities(id) ON DELETE CASCADE;"
|
ALTER TABLE notifications
|
||||||
|
ALTER COLUMN activity_id SET DATA TYPE uuid USING CAST( LPAD( TO_HEX(activity_id), 32, '0' ) AS uuid),
|
||||||
|
ADD CONSTRAINT notifications_activity_id_fkey FOREIGN KEY (activity_id) REFERENCES activities(id) ON DELETE CASCADE;
|
||||||
|
"""
|
||||||
|
|
||||||
for table <- ~w(notifications filters lists oauth_authorizations oauth_tokens password_reset_tokens push_subscriptions websub_client_subscriptions) do
|
for table <- ~w(notifications filters lists oauth_authorizations oauth_tokens password_reset_tokens push_subscriptions websub_client_subscriptions) do
|
||||||
execute "ALTER TABLE #{table} ALTER COLUMN user_id SET DATA TYPE uuid USING CAST( LPAD( TO_HEX(user_id), 32, '0' ) AS uuid);"
|
execute """
|
||||||
execute "ALTER TABLE #{table} ADD CONSTRAINT #{table}_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;"
|
ALTER TABLE #{table}
|
||||||
|
ALTER COLUMN user_id SET DATA TYPE uuid USING CAST( LPAD( TO_HEX(user_id), 32, '0' ) AS uuid),
|
||||||
|
ADD CONSTRAINT #{table}_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
|
||||||
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
stop_clippy_heartbeats(clippy)
|
stop_clippy_heartbeats(clippy)
|
||||||
|
|
Loading…
Reference in a new issue