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

52 lines
1 KiB
Python
Raw Normal View History

2022-10-17 09:35:26 +00:00
"""init tables
2022-10-14 15:05:04 +00:00
2022-10-17 09:35:26 +00:00
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()
2022-10-14 15:05:04 +00:00
init_users_query = """
2022-10-15 15:28:02 +00:00
CREATE TABLE users (
user_id bigint PRIMARY KEY,
2022-10-16 13:29:21 +00:00
chat_id bigint
2022-10-14 15:05:04 +00:00
);
"""
2022-10-17 09:35:26 +00:00
conn.execute(text(init_users_query))
2022-10-15 14:17:10 +00:00
2022-10-14 15:05:04 +00:00
init_projects_query = """
CREATE TABLE projects (
2022-10-15 15:28:02 +00:00
id SERIAL PRIMARY KEY,
name varchar(50),
description varchar(1000),
creator bigint REFERENCES users,
contributors smallint DEFAULT 1,
2022-10-22 12:11:43 +00:00
status int DEFAULT 1,
2022-10-17 10:56:54 +00:00
tag varchar(50) UNIQUE,
category varchar(50) UNIQUE,
2022-10-15 15:28:02 +00:00
creation_date date DEFAULT CURRENT_DATE
2022-10-14 15:05:04 +00:00
);
"""
2022-10-17 09:35:26 +00:00
conn.execute(text(init_projects_query))
2022-10-14 15:05:04 +00:00
2022-10-17 09:35:26 +00:00
def downgrade() -> None:
conn = op.get_bind()
2022-10-14 15:05:04 +00:00
2022-10-17 09:35:26 +00:00
conn.execute(text(
2022-10-17 10:56:54 +00:00
"DROP TABLE users, projects CASCADE"
2022-10-17 09:35:26 +00:00
))