diff options
Diffstat (limited to 'server/initializers/migrations')
-rw-r--r-- | server/initializers/migrations/0130-video-channel-actor.ts | 53 |
1 files changed, 36 insertions, 17 deletions
diff --git a/server/initializers/migrations/0130-video-channel-actor.ts b/server/initializers/migrations/0130-video-channel-actor.ts index 2e4694a75..fab77cf4a 100644 --- a/server/initializers/migrations/0130-video-channel-actor.ts +++ b/server/initializers/migrations/0130-video-channel-actor.ts | |||
@@ -99,7 +99,11 @@ async function up (utils: { | |||
99 | const data = { | 99 | const data = { |
100 | type: DataType.INTEGER, | 100 | type: DataType.INTEGER, |
101 | allowNull: true, | 101 | allowNull: true, |
102 | defaultValue: null | 102 | references: { |
103 | model: 'actor', | ||
104 | key: 'id' | ||
105 | }, | ||
106 | onDelete: 'CASCADE' | ||
103 | } | 107 | } |
104 | await utils.queryInterface.addColumn('account', 'actorId', data) | 108 | await utils.queryInterface.addColumn('account', 'actorId', data) |
105 | 109 | ||
@@ -108,11 +112,6 @@ async function up (utils: { | |||
108 | 112 | ||
109 | data.allowNull = false | 113 | data.allowNull = false |
110 | await utils.queryInterface.changeColumn('account', 'actorId', data) | 114 | await utils.queryInterface.changeColumn('account', 'actorId', data) |
111 | |||
112 | const query2 = `ALTER TABLE ONLY account | ||
113 | ADD CONSTRAINT "account_actorId_fkey" FOREIGN KEY ("actorId") REFERENCES actor(id) ON UPDATE CASCADE ON DELETE CASCADE; | ||
114 | ` | ||
115 | await utils.sequelize.query(query2) | ||
116 | } | 115 | } |
117 | 116 | ||
118 | { | 117 | { |
@@ -136,7 +135,11 @@ async function up (utils: { | |||
136 | const data = { | 135 | const data = { |
137 | type: DataType.INTEGER, | 136 | type: DataType.INTEGER, |
138 | allowNull: true, | 137 | allowNull: true, |
139 | defaultValue: null | 138 | references: { |
139 | model: 'actor', | ||
140 | key: 'id' | ||
141 | }, | ||
142 | onDelete: 'CASCADE' | ||
140 | } | 143 | } |
141 | await utils.queryInterface.addColumn('videoChannel', 'actorId', data) | 144 | await utils.queryInterface.addColumn('videoChannel', 'actorId', data) |
142 | 145 | ||
@@ -145,12 +148,6 @@ async function up (utils: { | |||
145 | 148 | ||
146 | data.allowNull = false | 149 | data.allowNull = false |
147 | await utils.queryInterface.changeColumn('videoChannel', 'actorId', data) | 150 | await utils.queryInterface.changeColumn('videoChannel', 'actorId', data) |
148 | |||
149 | const query2 = ` | ||
150 | ALTER TABLE ONLY "videoChannel" | ||
151 | ADD CONSTRAINT "videoChannel_actorId_fkey" FOREIGN KEY ("actorId") REFERENCES actor(id) ON UPDATE CASCADE ON DELETE CASCADE; | ||
152 | ` | ||
153 | await utils.sequelize.query(query2) | ||
154 | } | 151 | } |
155 | 152 | ||
156 | { | 153 | { |
@@ -166,16 +163,28 @@ async function up (utils: { | |||
166 | await utils.queryInterface.removeConstraint('actorFollow', 'accountFollow_targetAccountId_fkey') | 163 | await utils.queryInterface.removeConstraint('actorFollow', 'accountFollow_targetAccountId_fkey') |
167 | } | 164 | } |
168 | 165 | ||
169 | const query1 = `UPDATE "actorFollow" | 166 | { |
167 | const query1 = `UPDATE "actorFollow" | ||
170 | SET "actorId" = | 168 | SET "actorId" = |
171 | (SELECT "account"."actorId" FROM account WHERE "account"."id" = "actorFollow"."actorId")` | 169 | (SELECT "account"."actorId" FROM account WHERE "account"."id" = "actorFollow"."actorId")` |
172 | await utils.sequelize.query(query1) | 170 | await utils.sequelize.query(query1) |
173 | 171 | ||
174 | const query2 = `UPDATE "actorFollow" | 172 | const query2 = `UPDATE "actorFollow" |
175 | SET "targetActorId" = | 173 | SET "targetActorId" = |
176 | (SELECT "account"."actorId" FROM account WHERE "account"."id" = "actorFollow"."targetActorId")` | 174 | (SELECT "account"."actorId" FROM account WHERE "account"."id" = "actorFollow"."targetActorId")` |
177 | 175 | ||
178 | await utils.sequelize.query(query2) | 176 | await utils.sequelize.query(query2) |
177 | } | ||
178 | |||
179 | { | ||
180 | const query1 = `ALTER TABLE ONLY "actorFollow" | ||
181 | ADD CONSTRAINT "actorFollow_actorId_fkey" FOREIGN KEY ("actorId") REFERENCES actor(id) ON UPDATE CASCADE ON DELETE CASCADE;` | ||
182 | await utils.sequelize.query(query1) | ||
183 | |||
184 | const query2 = `ALTER TABLE ONLY "actorFollow" | ||
185 | ADD CONSTRAINT "actorFollow_targetActorId_fkey" FOREIGN KEY ("targetActorId") REFERENCES actor(id) ON UPDATE CASCADE ON DELETE CASCADE;` | ||
186 | await utils.sequelize.query(query2) | ||
187 | } | ||
179 | } | 188 | } |
180 | 189 | ||
181 | { | 190 | { |
@@ -191,6 +200,16 @@ async function up (utils: { | |||
191 | SET "actorId" = | 200 | SET "actorId" = |
192 | (SELECT "actorId" FROM account WHERE id = "videoShare"."actorId")` | 201 | (SELECT "actorId" FROM account WHERE id = "videoShare"."actorId")` |
193 | await utils.sequelize.query(query) | 202 | await utils.sequelize.query(query) |
203 | |||
204 | { | ||
205 | const query1 = `ALTER TABLE ONLY "videoShare" | ||
206 | ADD CONSTRAINT "videoShare_actorId_fkey" FOREIGN KEY ("actorId") REFERENCES actor(id) ON UPDATE CASCADE ON DELETE CASCADE;` | ||
207 | await utils.sequelize.query(query1) | ||
208 | |||
209 | const query2 = `ALTER TABLE ONLY "videoShare" | ||
210 | ADD CONSTRAINT "videoShare_videoId_fkey" FOREIGN KEY ("videoId") REFERENCES video(id) ON UPDATE CASCADE ON DELETE CASCADE;` | ||
211 | await utils.sequelize.query(query2) | ||
212 | } | ||
194 | } | 213 | } |
195 | 214 | ||
196 | { | 215 | { |