Ensure tweet ids are unique

This commit is contained in:
Jordan Eldredge 2020-12-02 02:50:46 -05:00
parent 039d3ea8c6
commit 16ec917b41

View file

@ -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<any> {
await knex.raw(
"CREATE UNIQUE INDEX idx_tweets_unique_tweet_id ON tweets(tweet_id);"
);
}
export async function down(knex: Knex): Promise<any> {
await knex.raw("DROP INDEX idx_tweets_unique_tweet_id");
}