Skip to content

Commit

Permalink
⚙️ Added ID column (as PK) to the tweets table and implemented an uni…
Browse files Browse the repository at this point in the history
…que constrain in the hash and search_criteria_id columns
  • Loading branch information
lhbelfanti committed Jul 30, 2024
1 parent 9387f89 commit 346beef
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion migrations/003_create_tweets_table.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CREATE TABLE IF NOT EXISTS tweets (
id SERIAL PRIMARY KEY,
hash TEXT NOT NULL,
posted_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
is_a_reply BOOLEAN NOT NULL,
Expand All @@ -7,12 +8,13 @@ CREATE TABLE IF NOT EXISTS tweets (
quote_id INTEGER NULL,
search_criteria_id INTEGER NOT NULL,

CONSTRAINT pk_tweets PRIMARY KEY (hash, search_criteria_id),
CONSTRAINT uq_hash_search_criteria UNIQUE (hash, search_criteria_id),
CONSTRAINT fk_quote_id FOREIGN KEY(quote_id) REFERENCES tweets_quotes(id),
CONSTRAINT fk_search_criteria_id FOREIGN KEY(search_criteria_id) REFERENCES search_criteria(id)
);

COMMENT ON TABLE tweets IS 'Contains the tweets scrapped by GoXCrap';
COMMENT ON COLUMN tweets.id IS 'Auto-incrementing ID of the tweet, agnostic to business logic';
COMMENT ON COLUMN tweets.hash IS 'Unique hash identifier for the tweet. It is part of the primary key';
COMMENT ON COLUMN tweets.posted_at IS 'Timestamp indicating when the tweet was posted';
COMMENT ON COLUMN tweets.is_a_reply IS 'Boolean indicating if the tweet is a reply to another tweet';
Expand Down

0 comments on commit 346beef

Please # to comment.