sqlite autoincrement support

drew/tilt-local-dev
Drew Bednar 2 years ago
parent 80a42f88aa
commit 815303693e

2
.gitignore vendored

@ -140,3 +140,5 @@ cython_debug/
# sqlite
*.sqlite3
.idea/

@ -20,7 +20,7 @@ def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"users",
sa.Column("id", sa.BigInteger(), autoincrement=True, nullable=False),
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("username", sa.String(length=128), nullable=False),
sa.Column("email", sa.String(length=128), nullable=False),
sa.PrimaryKeyConstraint("id"),

@ -1,4 +1,4 @@
from sqlalchemy import BigInteger, Column, String
from sqlalchemy import Integer, Column, String
from project.database import Base
@ -7,7 +7,7 @@ class User(Base):
__tablename__ = "users"
id = Column(BigInteger, primary_key=True, autoincrement=True)
id = Column(Integer, primary_key=True, autoincrement=True)
username = Column(String(128), unique=True, nullable=False)
email = Column(String(128), unique=True, nullable=False)

@ -16,7 +16,7 @@ def start_dev(c):
@task
def stop_dev(c):
"""Stops the developer environment."""
print("Stoping local development environment.")
print("Stopping local development environment...")
c.run("docker-compose -f docker-compose.yml down")
@ -48,6 +48,16 @@ def stop_redis(c):
c.run("docker compose -f docker-compose-redis.yml down")
@task
def init_db(c):
"""Initialize the database."""
from project.database import Base, engine
Base.metadata.bind = engine
Base.metadata.create_all()
print(f"Created: {engine.url}")
@task
def create_migration(c):
"""Creates a sqlalchemy migration."""
@ -62,8 +72,8 @@ def apply_migration(c, revision="head"):
@task(help={"username": "A username", "email": "The user's email"})
def add_user(c, username="", email=""):
"Adds a dummy user to the application Database"
if not username or email:
"""Adds a dummy user to the application Database"""
if not (username and email):
raise ValueError("You must provide a username and email")
from project.database import SessionLocal
from project.users.models import User

Loading…
Cancel
Save