Skip to content

Commit

Permalink
added migration for report
Browse files Browse the repository at this point in the history
  • Loading branch information
bomzheg committed Oct 24, 2023
1 parent 7ac92e7 commit c9da060
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
18 changes: 18 additions & 0 deletions migrations/05_add_report_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CREATE TABLE reports (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
reporter_id INT NOT NULL,
reported_user_id INT NOT NULL,
chat_id BIGINT NOT NULL,
created_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
resolution_time TIMESTAMP,
reported_message_id BIGINT NOT NULL,
reported_message_content VARCHAR(4096) NOT NULL,
resolved_by_id INT,
status varchar(32) NOT NULL,


CONSTRAINT reports_reporter_FK FOREIGN KEY (reporter_id) REFERENCES users(id),
CONSTRAINT reports_reported_user_FK FOREIGN KEY (reported_user_id) REFERENCES users(id),
CONSTRAINT reports_chat_FK FOREIGN KEY (chat_id) REFERENCES chats(chat_id),
CONSTRAINT reports_resolved_by_FK FOREIGN KEY (resolved_by_id) REFERENCES users(id)
);
15 changes: 15 additions & 0 deletions migrations/migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import sqlite3
import sys
from pathlib import Path

from app.config import load_config


db_config = load_config().db

with (Path(__file__).parent / sys.argv[1]).open() as f:
sql = f.read()

with sqlite3.connect(db_config.db_path) as conn:
cur = conn.cursor()
cur.execute(sql)

0 comments on commit c9da060

Please sign in to comment.