diff options
| author | Nathan Perry <avaglir@gmail.com> | 2018-04-05 22:52:02 -0400 |
|---|---|---|
| committer | Nathan Perry <avaglir@gmail.com> | 2018-04-05 22:52:02 -0400 |
| commit | ee1d099c6acdb38a173a7455804724f3a1b78836 (patch) | |
| tree | 0f4a8a949de370874d3e61788f5882dd7dddcf43 /migrations/2018-04-06-005800_consolidate_memes/up.sql | |
| parent | 1fda857d25c3d33e593951eef3ce713fa69a7025 (diff) | |
consolidate memes to one table
Diffstat (limited to 'migrations/2018-04-06-005800_consolidate_memes/up.sql')
| -rw-r--r-- | migrations/2018-04-06-005800_consolidate_memes/up.sql | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/migrations/2018-04-06-005800_consolidate_memes/up.sql b/migrations/2018-04-06-005800_consolidate_memes/up.sql new file mode 100644 index 0000000..084525b --- /dev/null +++ b/migrations/2018-04-06-005800_consolidate_memes/up.sql @@ -0,0 +1,19 @@ +ALTER TABLE text_memes ADD CONSTRAINT text_memes_content_not_all_null + CHECK (content IS NOT NULL OR image_id IS NOT NULL OR audio_id IS NOT NULL); + +ALTER TABLE text_memes ADD CONSTRAINT text_memes_image_or_audio_null + CHECK (image_id IS NULL OR audio_id IS NULL); + +ALTER TABLE text_memes ALTER COLUMN content DROP NOT NULL; + +INSERT INTO text_memes(audio_id, metadata_id, title) SELECT audio_id, metadata_id, title FROM audio_memes; +INSERT INTO text_memes(image_id, metadata_id, title) SELECT image_id, metadata_id, title FROM image_memes; + +DROP TABLE audio_memes; +DROP TABLE image_memes; + +ALTER TABLE text_memes RENAME TO memes; + +CREATE INDEX memes_audio ON memes (audio_id); +CREATE INDEX memes_image ON memes (image_id); +CREATE INDEX memes_content ON memes (content); |
