This repository has been archived on 2022-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
it-volunteers-for-peace/alembic/versions/9b42b5289e30_init_tables.py
2022-10-22 15:11:43 +03:00

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 int DEFAULT 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"
))