Refactor queries
This commit is contained in:
parent
092b81c53a
commit
c33248a0b2
|
@ -5,7 +5,9 @@ from asyncpg.connection import Connection
|
||||||
|
|
||||||
|
|
||||||
async def drop_tables(connection: Connection):
|
async def drop_tables(connection: Connection):
|
||||||
await connection.execute("DROP TABLE users, tags, categories, projects CASCADE")
|
await connection.execute(
|
||||||
|
"DROP TABLE users, tags, categories, projects CASCADE"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
|
|
|
@ -6,40 +6,40 @@ from asyncpg.connection import Connection
|
||||||
|
|
||||||
async def init_tables(connection: Connection):
|
async def init_tables(connection: Connection):
|
||||||
init_users_query = """
|
init_users_query = """
|
||||||
CREATE TABLE users ( \
|
CREATE TABLE users (
|
||||||
user_id bigint PRIMARY KEY, \
|
user_id bigint PRIMARY KEY,
|
||||||
is_admin boolean DEFAULT FALSE \
|
is_admin boolean DEFAULT FALSE
|
||||||
);
|
);
|
||||||
"""
|
"""
|
||||||
await connection.execute(init_users_query)
|
await connection.execute(init_users_query)
|
||||||
|
|
||||||
init_tags_query = """
|
init_tags_query = """
|
||||||
CREATE TABLE tags ( \
|
CREATE TABLE tags (
|
||||||
id SERIAL PRIMARY KEY, \
|
id SERIAL PRIMARY KEY,
|
||||||
name varchar(100) \
|
name varchar(100)
|
||||||
);
|
);
|
||||||
"""
|
"""
|
||||||
await connection.execute(init_tags_query)
|
await connection.execute(init_tags_query)
|
||||||
|
|
||||||
init_categories_query = """
|
init_categories_query = """
|
||||||
CREATE TABLE categories ( \
|
CREATE TABLE categories (
|
||||||
id SERIAL PRIMARY KEY, \
|
id SERIAL PRIMARY KEY,
|
||||||
name varchar(20) \
|
name varchar(20)
|
||||||
);
|
);
|
||||||
"""
|
"""
|
||||||
await connection.execute(init_categories_query)
|
await connection.execute(init_categories_query)
|
||||||
|
|
||||||
init_projects_query = """
|
init_projects_query = """
|
||||||
CREATE TABLE projects (
|
CREATE TABLE projects (
|
||||||
id SERIAL PRIMARY KEY, \
|
id SERIAL PRIMARY KEY,
|
||||||
name varchar(50), \
|
name varchar(50),
|
||||||
description varchar(1000), \
|
description varchar(1000),
|
||||||
creator bigint REFERENCES users, \
|
creator bigint REFERENCES users,
|
||||||
contributors smallint DEFAULT 1, \
|
contributors smallint DEFAULT 1,
|
||||||
status bit(1) DEFAULT B'1', \
|
status bit(1) DEFAULT B'1',
|
||||||
tag int REFERENCES tags, \
|
tag int REFERENCES tags,
|
||||||
category int REFERENCES categories, \
|
category int REFERENCES categories,
|
||||||
creation_date date DEFAULT CURRENT_DATE \
|
creation_date date DEFAULT CURRENT_DATE
|
||||||
);
|
);
|
||||||
"""
|
"""
|
||||||
await connection.execute(init_projects_query)
|
await connection.execute(init_projects_query)
|
||||||
|
|
Reference in a new issue