diff --git a/migrations/versions/f6ce1348e266_init.py b/migrations/versions/f6ce1348e266_init.py index 479676c5..80222218 100644 --- a/migrations/versions/f6ce1348e266_init.py +++ b/migrations/versions/f6ce1348e266_init.py @@ -17,21 +17,24 @@ depends_on = None def upgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - op.create_table( - "api_keys", - sa.Column("hashed_key", sqlm.sql.sqltypes.AutoString(), nullable=False), - sa.Column("balance", sa.Integer(), nullable=False), - sa.Column("refund_address", sqlm.sql.sqltypes.AutoString(), nullable=True), - sa.Column("key_expiry_time", sa.Integer(), nullable=True), - sa.Column("total_spent", sa.Integer(), nullable=False), - sa.Column("total_requests", sa.Integer(), nullable=False), - sa.PrimaryKeyConstraint("hashed_key"), - ) - # ### end Alembic commands ### + if "api_keys" not in sa.inspect(op.get_bind()).get_table_names(): + op.create_table( + "api_keys", + sa.Column("hashed_key", sqlm.sql.sqltypes.AutoString(), nullable=False), + sa.Column("balance", sa.Integer(), nullable=False), + sa.Column("refund_address", sqlm.sql.sqltypes.AutoString(), nullable=True), + sa.Column("key_expiry_time", sa.Integer(), nullable=True), + sa.Column("total_spent", sa.Integer(), nullable=False), + sa.Column("total_requests", sa.Integer(), nullable=False), + sa.PrimaryKeyConstraint("hashed_key"), + ) def downgrade() -> None: - # ### commands auto generated by Alembic - please adjust! ### - op.drop_table("api_keys") - # ### end Alembic commands ### + # Only drop the table if it exists + conn = op.get_bind() + inspector = sa.inspect(conn) + tables = inspector.get_table_names() + + if "api_keys" in tables: + op.drop_table("api_keys") diff --git a/setup.py b/setup.py index 4d7fd57a..c6f07fec 100644 --- a/setup.py +++ b/setup.py @@ -16,4 +16,4 @@ setup( "marshmallow>=3.13,<4.0", ], python_requires=">=3.11", -) \ No newline at end of file +)