Compare commits
2 commits
aa1e630809
...
f91bc1b826
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f91bc1b826 | ||
|
|
c1ceb65d04 |
1 changed files with 26 additions and 0 deletions
26
backend/add_reaction_table.py
Normal file
26
backend/add_reaction_table.py
Normal file
|
|
@ -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()
|
||||||
Loading…
Add table
Reference in a new issue