diff --git a/backend/add_reaction_table.py b/backend/add_reaction_table.py new file mode 100644 index 0000000..cbead91 --- /dev/null +++ b/backend/add_reaction_table.py @@ -0,0 +1,26 @@ +from sqlmodel import Session, create_engine, text +from database import DATABASE_URL + +def add_reaction_table(): + engine = create_engine(DATABASE_URL) + with Session(engine) as session: + try: + session.exec(text(""" + CREATE TABLE IF NOT EXISTS reaction ( + id SERIAL PRIMARY KEY, + user_id INTEGER NOT NULL REFERENCES "user"(id), + entity_type VARCHAR NOT NULL, + entity_id INTEGER NOT NULL, + emoji VARCHAR NOT NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ) + """)) + session.exec(text("CREATE INDEX IF NOT EXISTS ix_reaction_entity_type ON reaction (entity_type)")) + session.exec(text("CREATE INDEX IF NOT EXISTS ix_reaction_entity_id ON reaction (entity_id)")) + session.commit() + print("Successfully created reaction table") + except Exception as e: + print(f"Error creating table: {e}") + +if __name__ == "__main__": + add_reaction_table()