Merge branch 'main' into production
Some checks are pending
Deploy Elmeg / deploy (push) Waiting to run
Some checks are pending
Deploy Elmeg / deploy (push) Waiting to run
# Please enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
This commit is contained in:
commit
f91bc1b826
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