52 lines
1 KiB
Python
52 lines
1 KiB
Python
"""init tables
|
|
|
|
Revision ID: 9b42b5289e30
|
|
Revises:
|
|
Create Date: 2022-10-17 11:43:07.452838
|
|
|
|
"""
|
|
from alembic import op
|
|
from sqlalchemy.sql import text
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '9b42b5289e30'
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
conn = op.get_bind()
|
|
|
|
init_users_query = """
|
|
CREATE TABLE users (
|
|
user_id bigint PRIMARY KEY,
|
|
chat_id bigint
|
|
);
|
|
"""
|
|
conn.execute(text(init_users_query))
|
|
|
|
init_projects_query = """
|
|
CREATE TABLE projects (
|
|
id SERIAL PRIMARY KEY,
|
|
name varchar(50),
|
|
description varchar(1000),
|
|
creator bigint REFERENCES users,
|
|
contributors smallint DEFAULT 1,
|
|
status bit(1) DEFAULT B'1',
|
|
tag varchar(50) UNIQUE,
|
|
category varchar(50) UNIQUE,
|
|
creation_date date DEFAULT CURRENT_DATE
|
|
);
|
|
"""
|
|
conn.execute(text(init_projects_query))
|
|
|
|
|
|
def downgrade() -> None:
|
|
conn = op.get_bind()
|
|
|
|
conn.execute(text(
|
|
"DROP TABLE users, projects CASCADE"
|
|
))
|