-- start a transaction, so we won't leave the db in a halfway state if -- things go wrong BEGIN;
-- we need to add back some columns that Firefish removed, but that -- Sharkey migrations expect ALTERTABLE "user_profile" ADD "integrations" JSONB NOTNULLDEFAULT'{}'; ALTERTABLE "meta" ADD "twitterConsumerSecret" VARCHAR(128); ALTERTABLE "meta" ADD "twitterConsumerKey" VARCHAR(128); ALTERTABLE "meta" ADD "enableTwitterIntegration" BOOLEANNOTNULLDEFAULTfalse; ALTERTABLE "meta" ADD "enableGithubIntegration" BOOLEANNOTNULLDEFAULTfalse; ALTERTABLE "meta" ADD "githubClientId" VARCHAR(128); ALTERTABLE "meta" ADD "githubClientSecret" VARCHAR(128); ALTERTABLE "meta" ADD "enableDiscordIntegration" BOOLEANNOTNULLDEFAULTfalse; ALTERTABLE "meta" ADD "discordClientId" VARCHAR(128); ALTERTABLE "meta" ADD "discordClientSecret" VARCHAR(128);
-- also an extra table, for the same reasons CREATETABLE antenna_note();
-- Misskey used to have a Reversi game, Firefish dropped the tables, -- now Misskey uses them again CREATETABLE "reversi_game" ("id" charactervarying(32) NOTNULL, "createdAt" TIMESTAMPWITHTIME ZONE NOTNULL, "startedAt" TIMESTAMPWITHTIME ZONE, "user1Id" charactervarying(32) NOTNULL, "user2Id" charactervarying(32) NOTNULL, "user1Accepted" booleanNOTNULLDEFAULTfalse, "user2Accepted" booleanNOTNULLDEFAULTfalse, "black" integer, "isStarted" booleanNOTNULLDEFAULTfalse, "isEnded" booleanNOTNULLDEFAULTfalse, "winnerId" charactervarying(32), "surrendered" charactervarying(32), "logs" jsonb NOTNULLDEFAULT'[]', "map" charactervarying(64) arrayNOTNULL, "bw" charactervarying(32) NOTNULL, "isLlotheo" booleanNOTNULLDEFAULTfalse, "canPutEverywhere" booleanNOTNULLDEFAULTfalse, "loopedBoard" booleanNOTNULLDEFAULTfalse, "form1" jsonb DEFAULTnull, "form2" jsonb DEFAULTnull, "crc32" charactervarying(32), CONSTRAINT "PK_76b30eeba71b1193ad7c5311c3f" PRIMARY KEY ("id")); CREATE INDEX "IDX_b46ec40746efceac604142be1c" ON "reversi_game" ("createdAt"); CREATETABLE "reversi_matching" ("id" charactervarying(32) NOTNULL, "createdAt" TIMESTAMPWITHTIME ZONE NOTNULL, "parentId" charactervarying(32) NOTNULL, "childId" charactervarying(32) NOTNULL, CONSTRAINT "PK_880bd0afbab232f21c8b9d146cf" PRIMARY KEY ("id")); CREATE INDEX "IDX_b604d92d6c7aec38627f6eaf16" ON "reversi_matching" ("createdAt"); CREATE INDEX "IDX_3b25402709dd9882048c2bbade" ON "reversi_matching" ("parentId"); CREATE INDEX "IDX_e247b23a3c9b45f89ec1299d06" ON "reversi_matching" ("childId");
-- move aside some FireFish columns; Sharkey migrations will -- re-create them; we don't `DROP` them because we want to keep the data ALTERTABLE "user" RENAME COLUMN "movedToUri" TO "ff_movedToUri"; ALTERTABLE "user" RENAME COLUMN "alsoKnownAs" TO "ff_alsoKnownAs"; ALTERTABLE "user" RENAME COLUMN "isIndexable" TO "ff_isIndexable"; ALTERTABLE "user" RENAME COLUMN "speakAsCat" TO "ff_speakAsCat"; ALTERTABLE "user_profile" RENAME COLUMN "preventAiLearning" TO "ff_preventAiLearning"; ALTERTABLE "meta" RENAME COLUMN "silencedHosts" TO "ff_silencedHosts";
-- this column was added by both Firefish and Misskey, but with -- different names, let's fix it ALTERTABLE "meta" RENAME COLUMN "ToSUrl" TO "termsOfServiceUrl";
-- update antenna types, this is only needed on some instances but -- recommend to run anyway -- -- this *removes* any antennas of types not supported by Sharkey! CREATE TYPE public.new_antenna_src_enum AS ENUM ('home', 'all', 'list'); ALTERTABLE antenna ADDCOLUMN new_src public.new_antenna_src_enum; DELETEFROM antenna WHERE src NOTIN ('home', 'all', 'list'); ALTERTABLE antenna DROPCOLUMN src; ALTERTABLE antenna RENAME COLUMN new_src TO src; DROP TYPE public.antenna_src_enum; ALTER TYPE new_antenna_src_enum RENAME TO antenna_src_enum;
-- optional but recommended: delete all empty moderation log entries DELETEFROM moderation_log WHERE info ='{}';
-- only needed on some instances, run this if -- `\dT+ user_profile_mutingnotificationtypes_enum` -- does not show `note` in the "elements" section ALTER TYPE "public"."user_profile_mutingnotificationtypes_enum" ADDVALUE'note';
如果有任何报错信息,请停止迁移!除非你真的知道自己在干什么,不要乱动数据库。去 Sharkey 提供的 Matrix or Discord 求助。
-- all existing users are approved, because Firefish doesn't have a -- concept of approvals UPDATE "user" SET approved =true;
-- now we put back the data we moved aside UPDATE "user" SET "movedToUri" = "ff_movedToUri" WHERE "ff_movedToUri" ISNOTNULL; UPDATE "user" SET "alsoKnownAs" = "ff_alsoKnownAs" WHERE "ff_alsoKnownAs" ISNOTNULL; UPDATE "user" SET "noindex" =NOT (COALESCE("ff_isIndexable", true)); UPDATE "user" SET "speakAsCat" =COALESCE("ff_speakAsCat", false); UPDATE "user_profile" SET "preventAiLearning" =COALESCE("ff_preventAiLearning", true); UPDATE "meta" SET "silencedHosts" =COALESCE("ff_silencedHosts",'{}');
GRANTALL PRIVILEGES ONALL TABLES IN SCHEMA public TO your_user;
然后将所有表格的owner设置成你的用户
DO $$ DECLARE r RECORD; BEGIN FOR r IN SELECT table_schema, table_name FROM information_schema.tables WHERE table_schema NOTIN ('pg_catalog', 'information_schema') AND table_type ='BASE TABLE' LOOP EXECUTE'ALTER TABLE '|| r.table_schema ||'.'|| r.table_name ||' OWNER TO your_user'; END LOOP; END; $$;
DO $$ DECLARE r RECORD; BEGIN FOR r IN SELECT n.nspname AS schema_name, t.typname AS type_name FROM pg_type t JOIN pg_namespace n ON n.oid = t.typnamespace WHERE t.typowner <> (SELECT oid FROM pg_roles WHERE rolname ='firefish') AND n.nspname NOTIN ('pg_catalog', 'information_schema') AND t.typtype ='e'-- 仅针对枚举类型(自定义类型) LOOP EXECUTE'ALTER TYPE '|| r.schema_name ||'.'|| r.type_name ||' OWNER TO your_user'; END LOOP; END; $$;