-
Notifications
You must be signed in to change notification settings - Fork 10
/
migrate.sql
593 lines (442 loc) · 18.6 KB
/
migrate.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
-- This script was generated by the Schema Diff utility in pgAdmin 4, but heavily modified by me
-- (circuitsacul).
-- This script was generated by the Schema Diff utility in pgAdmin 4.
-- For the circular dependencies, the order in which Schema Diff writes the objects is not very sophisticated
-- and may require manual changes to the script to ensure changes are applied in the correct order.
-- Please report an issue for any failure with the reproduction steps.
BEGIN;
-- manual
alter table aschannels rename to autostar_channels;
alter table sb_messages rename to starboard_messages;
alter table autostar_channels rename prem_locked to premium_locked;
alter table starboards rename prem_locked to premium_locked;
alter table starboards rename remove_invalid to remove_invalid_reactions;
alter table starboard_messages rename sb_message_id to starboard_message_id;
alter table overrides rename _overrides to overrides;
alter table permroles rename xproles to obtain_xproles;
alter table permroles rename vote to give_votes;
alter table permroles rename recv_votes to receive_votes;
alter table permrole_starboards rename vote to give_votes;
alter table permrole_starboards rename recv_votes to receive_votes;
alter sequence aschannels_id_seq rename to autostar_channels_id_seq;
delete from starboard_messages where starboard_message_id is null;
-- drop foreign keys
ALTER TABLE public.xproles DROP CONSTRAINT guild_id_fk;
ALTER TABLE public.votes DROP CONSTRAINT message_id_fk;
ALTER TABLE public.votes DROP CONSTRAINT starboard_id_fk;
ALTER TABLE public.votes DROP CONSTRAINT target_author_id_fk;
ALTER TABLE public.votes DROP CONSTRAINT user_id_fk;
ALTER TABLE public.overrides DROP CONSTRAINT guild_fk;
ALTER TABLE public.overrides DROP CONSTRAINT starboard_fk;
ALTER TABLE public.autostar_channels DROP CONSTRAINT guild_id_fk;
ALTER TABLE public.permrole_starboards DROP CONSTRAINT permrole_id_fk;
ALTER TABLE public.permrole_starboards DROP CONSTRAINT starboard_id_fk;
ALTER TABLE public.permroles DROP CONSTRAINT guild_id_fk;
ALTER TABLE public.members DROP CONSTRAINT guildid_fk;
ALTER TABLE public.members DROP CONSTRAINT userid_fk;
ALTER TABLE public.messages DROP CONSTRAINT author_id_fk;
ALTER TABLE public.messages DROP CONSTRAINT guild_id_fk;
ALTER TABLE public.posroles DROP CONSTRAINT guild_id_fk;
ALTER TABLE public.starboards DROP CONSTRAINT guild_id_fk;
ALTER TABLE public.starboard_messages DROP CONSTRAINT message_id_fk;
ALTER TABLE public.starboard_messages DROP CONSTRAINT starboard_id_fk;
ALTER TABLE public.posrole_members DROP CONSTRAINT role_id_fk;
ALTER TABLE public.posrole_members DROP CONSTRAINT user_id_fk;
-- misc
DROP TABLE public._migrations CASCADE;
-- users
ALTER TABLE public.users
ALTER COLUMN user_id TYPE bigint;
ALTER TABLE public.users
ALTER COLUMN user_id SET STORAGE PLAIN;
ALTER TABLE public.users
ALTER COLUMN credits SET DEFAULT 0;
ALTER TABLE public.users
ALTER COLUMN donated_cents SET DEFAULT 0;
ALTER TABLE public.users
ALTER COLUMN patreon_status SET DEFAULT 0;
ALTER TABLE public.users DROP CONSTRAINT _users_user_id_primary_key;
ALTER TABLE public.users
ADD CONSTRAINT users_pkey PRIMARY KEY (user_id);
-- patrons
ALTER TABLE public.patrons
ALTER COLUMN discord_id TYPE bigint;
ALTER TABLE public.patrons
ALTER COLUMN discord_id SET STORAGE PLAIN;
ALTER TABLE public.patrons
ALTER COLUMN last_patreon_total_cents SET DEFAULT 0;
ALTER TABLE public.patrons DROP CONSTRAINT _patrons_patreon_id_primary_key;
ALTER TABLE public.patrons
ADD CONSTRAINT patrons_pkey PRIMARY KEY (patreon_id);
ALTER TABLE public.patrons
ADD CONSTRAINT patrons_discord_id_fkey FOREIGN KEY (discord_id)
REFERENCES public.users (user_id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE RESTRICT;
DROP INDEX public._btree_index_patrons__discord_id;
-- guilds
ALTER TABLE public.guilds
ALTER COLUMN guild_id TYPE bigint;
ALTER TABLE public.guilds
ALTER COLUMN guild_id SET STORAGE PLAIN;
ALTER TABLE public.guilds DROP CONSTRAINT _guilds_guild_id_primary_key;
ALTER TABLE public.guilds
ADD CONSTRAINT guilds_pkey PRIMARY KEY (guild_id);
DROP INDEX public._btree_index_guilds__premium_end;
-- messages
ALTER TABLE public.messages
ALTER COLUMN message_id TYPE bigint;
ALTER TABLE public.messages
ALTER COLUMN message_id SET STORAGE PLAIN;
ALTER TABLE public.messages
ALTER COLUMN guild_id TYPE bigint;
ALTER TABLE public.messages
ALTER COLUMN guild_id SET STORAGE PLAIN;
ALTER TABLE public.messages
ALTER COLUMN channel_id TYPE bigint;
ALTER TABLE public.messages
ALTER COLUMN channel_id SET STORAGE PLAIN;
ALTER TABLE public.messages
ALTER COLUMN author_id TYPE bigint;
ALTER TABLE public.messages
ALTER COLUMN author_id SET STORAGE PLAIN;
ALTER TABLE public.messages
ALTER COLUMN forced_to SET DEFAULT '{}'::integer[];
ALTER TABLE public.messages
ALTER COLUMN trashed SET DEFAULT false;
ALTER TABLE public.messages
ALTER COLUMN trash_reason TYPE character varying COLLATE pg_catalog."default";
ALTER TABLE public.messages
ALTER COLUMN frozen SET DEFAULT false;
ALTER TABLE public.messages DROP CONSTRAINT _messages_message_id_primary_key;
ALTER TABLE public.messages
ADD CONSTRAINT messages_pkey PRIMARY KEY (message_id);
ALTER TABLE public.messages
ADD CONSTRAINT messages_author_id_fkey FOREIGN KEY (author_id)
REFERENCES public.users (user_id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;
ALTER TABLE public.messages
ADD CONSTRAINT messages_guild_id_fkey FOREIGN KEY (guild_id)
REFERENCES public.guilds (guild_id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;
-- members
ALTER TABLE public.members
ALTER COLUMN user_id TYPE bigint;
ALTER TABLE public.members
ALTER COLUMN user_id SET STORAGE PLAIN;
ALTER TABLE public.members
ALTER COLUMN guild_id TYPE bigint;
ALTER TABLE public.members
ALTER COLUMN guild_id SET STORAGE PLAIN;
ALTER TABLE public.members
ALTER COLUMN xp SET DEFAULT 0;
ALTER TABLE public.members
ALTER COLUMN autoredeem_enabled SET DEFAULT false;
ALTER TABLE public.members DROP CONSTRAINT _members_user_id_guild_id_primary_key;
ALTER TABLE public.members
ADD CONSTRAINT members_pkey PRIMARY KEY (user_id, guild_id);
ALTER TABLE public.members
ADD CONSTRAINT members_guild_id_fkey FOREIGN KEY (guild_id)
REFERENCES public.guilds (guild_id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;
ALTER TABLE public.members
ADD CONSTRAINT members_user_id_fkey FOREIGN KEY (user_id)
REFERENCES public.users (user_id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;
DROP INDEX public._btree_index_members__autoredeem_enabled;
DROP INDEX public._btree_index_members__xp;
DROP INDEX public._btree_index_members__guild_id;
-- starboards
ALTER TABLE public.starboards
ALTER COLUMN channel_id TYPE bigint;
ALTER TABLE public.starboards
ALTER COLUMN channel_id SET STORAGE PLAIN;
ALTER TABLE public.starboards
ALTER COLUMN guild_id TYPE bigint;
ALTER TABLE public.starboards
ALTER COLUMN guild_id SET STORAGE PLAIN;
ALTER TABLE public.starboards
ALTER COLUMN webhook_id TYPE bigint;
ALTER TABLE public.starboards
ALTER COLUMN webhook_id SET STORAGE PLAIN;
ALTER TABLE public.starboards
ALTER COLUMN premium_locked SET DEFAULT false;
ALTER TABLE public.starboards
ALTER COLUMN display_emoji SET DEFAULT '⭐'::text;
ALTER TABLE public.starboards
ALTER COLUMN ping_author SET DEFAULT false;
ALTER TABLE public.starboards
ALTER COLUMN use_server_profile SET DEFAULT true;
ALTER TABLE public.starboards
ALTER COLUMN extra_embeds SET DEFAULT true;
ALTER TABLE public.starboards
ALTER COLUMN use_webhook SET DEFAULT false;
ALTER TABLE public.starboards
ALTER COLUMN color DROP NOT NULL;
ALTER TABLE public.starboards
ALTER COLUMN jump_to_message SET DEFAULT true;
ALTER TABLE public.starboards
ALTER COLUMN attachments_list SET DEFAULT true;
ALTER TABLE public.starboards
ALTER COLUMN replied_to SET DEFAULT true;
ALTER TABLE public.starboards
ALTER COLUMN required SET DEFAULT 3;
ALTER TABLE public.starboards
ALTER COLUMN required_remove SET DEFAULT 0;
ALTER TABLE public.starboards
ALTER COLUMN upvote_emojis SET DEFAULT '{⭐}'::text[];
ALTER TABLE public.starboards
ALTER COLUMN downvote_emojis SET DEFAULT '{}'::text[];
ALTER TABLE public.starboards
ALTER COLUMN self_vote SET DEFAULT false;
ALTER TABLE public.starboards
ALTER COLUMN allow_bots SET DEFAULT true;
ALTER TABLE public.starboards
ALTER COLUMN require_image SET DEFAULT false;
ALTER TABLE public.starboards
ALTER COLUMN older_than SET DEFAULT 0;
ALTER TABLE public.starboards
ALTER COLUMN newer_than SET DEFAULT 0;
ALTER TABLE public.starboards
ALTER COLUMN enabled SET DEFAULT true;
ALTER TABLE public.starboards
ALTER COLUMN autoreact_upvote SET DEFAULT true;
ALTER TABLE public.starboards
ALTER COLUMN autoreact_downvote SET DEFAULT true;
ALTER TABLE public.starboards
ALTER COLUMN remove_invalid_reactions SET DEFAULT true;
ALTER TABLE public.starboards
ALTER COLUMN link_deletes SET DEFAULT false;
ALTER TABLE public.starboards
ALTER COLUMN link_edits SET DEFAULT true;
ALTER TABLE public.starboards
ALTER COLUMN private SET DEFAULT false;
ALTER TABLE public.starboards
ALTER COLUMN xp_multiplier SET DEFAULT 1.0;
ALTER TABLE public.starboards
ALTER COLUMN cooldown_enabled SET DEFAULT false;
ALTER TABLE public.starboards
ALTER COLUMN cooldown_count SET DEFAULT 5;
ALTER TABLE public.starboards
ALTER COLUMN cooldown_period SET DEFAULT 5;
ALTER TABLE public.starboards DROP CONSTRAINT _starboards_id_primary_key;
ALTER TABLE public.starboards
ADD CONSTRAINT starboards_pkey PRIMARY KEY (id);
ALTER TABLE public.starboards DROP CONSTRAINT sb_guild_name_unique;
ALTER TABLE public.starboards
ADD CONSTRAINT starboards_guild_id_name_key UNIQUE (guild_id, name);
ALTER TABLE public.starboards
ADD CONSTRAINT starboards_guild_id_fkey FOREIGN KEY (guild_id)
REFERENCES public.guilds (guild_id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;
DROP INDEX public._btree_index_starboards__guild_id_name;
DROP INDEX public._btree_index_starboards__channel_id;
-- overrides
ALTER TABLE public.overrides
ALTER COLUMN guild_id TYPE bigint;
ALTER TABLE public.overrides
ALTER COLUMN guild_id SET STORAGE PLAIN;
ALTER TABLE public.overrides
ALTER COLUMN channel_ids TYPE bigint[];
ALTER TABLE public.overrides
ALTER COLUMN channel_ids SET DEFAULT '{}'::bigint[];
ALTER TABLE public.overrides
ALTER COLUMN overrides SET DEFAULT '{}'::json;
ALTER TABLE public.overrides DROP CONSTRAINT _overrides_id_primary_key;
ALTER TABLE public.overrides
ADD CONSTRAINT overrides_pkey PRIMARY KEY (id);
ALTER TABLE public.overrides
ADD CONSTRAINT overrides_guild_id_fkey FOREIGN KEY (guild_id)
REFERENCES public.guilds (guild_id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;
ALTER TABLE public.overrides
ADD CONSTRAINT overrides_starboard_id_fkey FOREIGN KEY (starboard_id)
REFERENCES public.starboards (id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;
DROP INDEX public._btree_index_overrides__starboard_id;
DROP INDEX public._btree_index_overrides__guild_id_name;
DROP INDEX public._gin_index_overrides__channel_ids;
-- xproles
ALTER TABLE public.xproles
ALTER COLUMN role_id TYPE bigint;
ALTER TABLE public.xproles
ALTER COLUMN role_id SET STORAGE PLAIN;
ALTER TABLE public.xproles
ALTER COLUMN guild_id TYPE bigint;
ALTER TABLE public.xproles
ALTER COLUMN guild_id SET STORAGE PLAIN;
ALTER TABLE public.xproles DROP CONSTRAINT _xproles_role_id_primary_key;
ALTER TABLE public.xproles
ADD CONSTRAINT xproles_pkey PRIMARY KEY (role_id);
ALTER TABLE public.xproles
ADD CONSTRAINT xproles_guild_id_fkey FOREIGN KEY (guild_id)
REFERENCES public.guilds (guild_id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;
DROP INDEX public._btree_index_xproles__guild_id;
-- votes
ALTER TABLE public.votes
ALTER COLUMN message_id TYPE bigint;
ALTER TABLE public.votes
ALTER COLUMN message_id SET STORAGE PLAIN;
ALTER TABLE public.votes
ALTER COLUMN user_id TYPE bigint;
ALTER TABLE public.votes
ALTER COLUMN user_id SET STORAGE PLAIN;
ALTER TABLE public.votes
ALTER COLUMN target_author_id TYPE bigint;
ALTER TABLE public.votes
ALTER COLUMN target_author_id SET STORAGE PLAIN;
ALTER TABLE public.votes DROP CONSTRAINT _votes_message_id_starboard_id_user_id_primary_key;
ALTER TABLE public.votes
ADD CONSTRAINT votes_pkey PRIMARY KEY (message_id, starboard_id, user_id);
ALTER TABLE public.votes
ADD CONSTRAINT votes_message_id_fkey FOREIGN KEY (message_id)
REFERENCES public.messages (message_id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;
ALTER TABLE public.votes
ADD CONSTRAINT votes_starboard_id_fkey FOREIGN KEY (starboard_id)
REFERENCES public.starboards (id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;
ALTER TABLE public.votes
ADD CONSTRAINT votes_target_author_id_fkey FOREIGN KEY (target_author_id)
REFERENCES public.users (user_id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;
ALTER TABLE public.votes
ADD CONSTRAINT votes_user_id_fkey FOREIGN KEY (user_id)
REFERENCES public.users (user_id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;
DROP INDEX public._btree_index_votes__target_author_id;
DROP INDEX public._btree_index_votes__user_id;
DROP INDEX public._btree_index_votes__message_id;
DROP INDEX public._btree_index_votes__is_downvote;
DROP INDEX public._btree_index_votes__starboard_id;
-- autostar_channels
ALTER TABLE public.autostar_channels
ALTER COLUMN channel_id TYPE bigint;
ALTER TABLE public.autostar_channels
ALTER COLUMN channel_id SET STORAGE PLAIN;
ALTER TABLE public.autostar_channels
ALTER COLUMN guild_id TYPE bigint;
ALTER TABLE public.autostar_channels
ALTER COLUMN guild_id SET STORAGE PLAIN;
ALTER TABLE public.autostar_channels
ALTER COLUMN premium_locked SET DEFAULT false;
ALTER TABLE public.autostar_channels
ALTER COLUMN emojis SET DEFAULT '{}'::text[];
ALTER TABLE public.autostar_channels
ALTER COLUMN min_chars SET DEFAULT 0;
ALTER TABLE public.autostar_channels
ALTER COLUMN require_image SET DEFAULT false;
ALTER TABLE public.autostar_channels
ALTER COLUMN delete_invalid SET DEFAULT false;
ALTER TABLE public.autostar_channels DROP CONSTRAINT _aschannels_id_primary_key;
ALTER TABLE public.autostar_channels
ADD CONSTRAINT autostar_channels_pkey PRIMARY KEY (id);
ALTER TABLE public.autostar_channels DROP CONSTRAINT asc_guild_name_unique;
ALTER TABLE public.autostar_channels
ADD CONSTRAINT autostar_channels_guild_id_name_key UNIQUE (guild_id, name);
ALTER TABLE public.autostar_channels
ADD CONSTRAINT autostar_channels_guild_id_fkey FOREIGN KEY (guild_id)
REFERENCES public.guilds (guild_id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;
DROP INDEX public._btree_index_aschannels__guild_id_name;
DROP INDEX public._btree_index_aschannels__channel_id;
-- permroles
ALTER TABLE public.permroles
ALTER COLUMN role_id SET STORAGE PLAIN;
ALTER TABLE public.permroles
ALTER COLUMN guild_id TYPE bigint;
ALTER TABLE public.permroles
ALTER COLUMN guild_id SET STORAGE PLAIN;
ALTER TABLE public.permroles DROP CONSTRAINT _permroles_role_id_primary_key;
ALTER TABLE public.permroles
ADD CONSTRAINT permroles_pkey PRIMARY KEY (role_id);
ALTER TABLE public.permroles
ADD CONSTRAINT permroles_guild_id_fkey FOREIGN KEY (guild_id)
REFERENCES public.guilds (guild_id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;
DROP INDEX public._btree_index_permroles__guild_id;
-- permrole_starboards
ALTER TABLE public.permrole_starboards
ALTER COLUMN permrole_id TYPE bigint;
ALTER TABLE public.permrole_starboards
ALTER COLUMN permrole_id SET STORAGE PLAIN;
ALTER TABLE public.permrole_starboards DROP CONSTRAINT _permrole_starboards_permrole_id_starboard_id_primary_key;
ALTER TABLE public.permrole_starboards
ADD CONSTRAINT permrole_starboards_pkey PRIMARY KEY (permrole_id, starboard_id);
ALTER TABLE public.permrole_starboards
ADD CONSTRAINT permrole_starboards_permrole_id_fkey FOREIGN KEY (permrole_id)
REFERENCES public.permroles (role_id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;
ALTER TABLE public.permrole_starboards
ADD CONSTRAINT permrole_starboards_starboard_id_fkey FOREIGN KEY (starboard_id)
REFERENCES public.starboards (id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;
ALTER TABLE public.permroles
ALTER COLUMN role_id TYPE bigint;
-- posroles
ALTER TABLE public.posroles
ALTER COLUMN role_id TYPE bigint;
ALTER TABLE public.posroles
ALTER COLUMN role_id SET STORAGE PLAIN;
ALTER TABLE public.posroles
ALTER COLUMN guild_id TYPE bigint;
ALTER TABLE public.posroles
ALTER COLUMN guild_id SET STORAGE PLAIN;
ALTER TABLE public.posroles DROP CONSTRAINT _posroles_role_id_primary_key;
ALTER TABLE public.posroles
ADD CONSTRAINT posroles_pkey PRIMARY KEY (role_id);
ALTER TABLE public.posroles
ADD CONSTRAINT posroles_guild_id_fkey FOREIGN KEY (guild_id)
REFERENCES public.guilds (guild_id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;
DROP INDEX public._btree_index_posroles__guild_id_max_members;
-- starboard_messages
ALTER TABLE public.starboard_messages
ALTER COLUMN message_id TYPE bigint;
ALTER TABLE public.starboard_messages
ALTER COLUMN message_id SET STORAGE PLAIN;
ALTER TABLE public.starboard_messages
ALTER COLUMN starboard_message_id TYPE bigint;
ALTER TABLE public.starboard_messages
ALTER COLUMN starboard_message_id SET NOT NULL;
ALTER TABLE public.starboard_messages
ALTER COLUMN starboard_message_id SET STORAGE PLAIN;
ALTER TABLE public.starboard_messages
ALTER COLUMN last_known_point_count SET DEFAULT 0;
ALTER TABLE public.starboard_messages DROP CONSTRAINT _sb_messages_message_id_starboard_id_primary_key;
ALTER TABLE public.starboard_messages
ADD CONSTRAINT starboard_messages_pkey PRIMARY KEY (message_id, starboard_id);
ALTER TABLE public.starboard_messages
ADD CONSTRAINT starboard_messages_message_id_fkey FOREIGN KEY (message_id)
REFERENCES public.messages (message_id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;
ALTER TABLE public.starboard_messages
ADD CONSTRAINT starboard_messages_starboard_id_fkey FOREIGN KEY (starboard_id)
REFERENCES public.starboards (id) MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE;
DROP INDEX public._btree_index_sb_messages__starboard_id;
DROP INDEX public._btree_index_sb_messages__last_known_point_count;
DROP INDEX public._btree_index_sb_messages__sb_message_id;
-- posrole_members
DROP TABLE posrole_members;
END;