From 16ec917b41fa47d4cdcd6aecc415189ff3e46cc3 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Wed, 2 Dec 2020 02:50:46 -0500 Subject: [PATCH] Ensure tweet ids are unique --- .../migrations/20201202021617_unique_tweet_ids.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 packages/skin-database/migrations/20201202021617_unique_tweet_ids.ts diff --git a/packages/skin-database/migrations/20201202021617_unique_tweet_ids.ts b/packages/skin-database/migrations/20201202021617_unique_tweet_ids.ts new file mode 100644 index 00000000..d8dd9097 --- /dev/null +++ b/packages/skin-database/migrations/20201202021617_unique_tweet_ids.ts @@ -0,0 +1,13 @@ +import * as Knex from "knex"; + +// We can't add a unique constraint after the fact, but we can add a unique index which should do the same thing. +// https://stackoverflow.com/a/35301957/1263117 +export async function up(knex: Knex): Promise { + await knex.raw( + "CREATE UNIQUE INDEX idx_tweets_unique_tweet_id ON tweets(tweet_id);" + ); +} + +export async function down(knex: Knex): Promise { + await knex.raw("DROP INDEX idx_tweets_unique_tweet_id"); +}