Skip to content

Commit

Permalink
Adicionando testes de migração entre as aulas 05 e 09
Browse files Browse the repository at this point in the history
  • Loading branch information
dunossauro committed May 30, 2024
1 parent 76c1809 commit 25275ce
Showing 1 changed file with 50 additions and 8 deletions.
58 changes: 50 additions & 8 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,39 @@
from pathlib import Path
from tomllib import loads

migration_05 = """CREATE TABLE alembic_version (
version_num VARCHAR(32) NOT NULL,
CONSTRAINT alembic_version_pkc PRIMARY KEY (version_num)
);
CREATE TABLE users (
id INTEGER NOT NULL,
username VARCHAR NOT NULL,
password VARCHAR NOT NULL,
email VARCHAR NOT NULL,
created_at DATETIME DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
PRIMARY KEY (id),
UNIQUE (email),
UNIQUE (username)
);
"""

# WIP: Ajustar o esperado dessa migração no código
migration_09 = """CREATE TABLE alembic_version (
version_num VARCHAR(32) NOT NULL,
CONSTRAINT alembic_version_pkc PRIMARY KEY (version_num)
);
CREATE TABLE users (
id INTEGER NOT NULL,
username VARCHAR NOT NULL,
password VARCHAR NOT NULL,
email VARCHAR NOT NULL,
created_at DATETIME DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
PRIMARY KEY (id),
UNIQUE (email),
UNIQUE (username)
);
"""


@task
def update_project(c):
Expand All @@ -29,7 +62,7 @@ def typos_sub(c):
for path in sorted(code_path):
print(path)
with c.cd(str(path)):
c.run(f'poetry run typos .')
c.run('poetry run typos .')


@task
Expand All @@ -38,7 +71,7 @@ def lint_sub(c):
for path in sorted(code_path):
print(path)
with c.cd(str(path)):
c.run(f'poetry run task lint')
c.run('poetry run task lint')


@task
Expand All @@ -57,9 +90,18 @@ def test_sub(c):
for path in sorted(code_path):
print(path)
with c.cd(str(path)):
c.run(f'poetry install')
c.run(f'poetry run task test')
c.run('poetry install')
c.run('poetry run task test')

if int(path.parts[-1]) >= 5:
c.run('alembic upgrade head')
schema = c.run('sqlite3 database.db ".schema"')
assert schema.stdout == migration_05

elif int(path.parts[-1]) >= 9:
c.run('alembic upgrade head')
schema = c.run('sqlite3 database.db ".schema"')
assert schema.stdout == migration_09

@task
def update_sub(c):
Expand All @@ -74,21 +116,21 @@ def update_sub(c):

print(path)
with c.cd(str(path)):
c.run(f'poetry update')
c.run('poetry update')
c.run('rm -rf .venv')
if (path / 'poetry.lock').exists():
c.run('rm poetry.lock')

for dep in sorted(dependencies):
print(dep, path)
if dep == 'pydantic':
c.run(f'poetry add "pydantic[email]@latest"')
c.run('poetry add "pydantic[email]@latest"')

elif dep == 'passlib':
c.run(f'poetry add "passlib[bcrypt]@latest"')
c.run('poetry add "passlib[bcrypt]@latest"')

elif dep == 'psycopg':
c.run(f'poetry add "psycopg[binary]@latest"')
c.run('poetry add "psycopg[binary]@latest"')

elif dep == 'python':
...
Expand Down

0 comments on commit 25275ce

Please sign in to comment.