mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-06 05:01:48 +02:00
Configure SQLite to disable ID reuse
This commit is contained in:
parent
d008e88f31
commit
e7848e39c6
2 changed files with 55 additions and 0 deletions
|
@ -0,0 +1,50 @@
|
|||
"""sqlite_autoincrement
|
||||
|
||||
Revision ID: cb038f79982e
|
||||
Revises: 2dcb0c0048dc
|
||||
Create Date: 2020-04-13 17:40:02.426957
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "cb038f79982e"
|
||||
down_revision = "2dcb0c0048dc"
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
alter_table_batches = [
|
||||
op.batch_alter_table(
|
||||
"person", recreate="always", table_kwargs={"sqlite_autoincrement": True}
|
||||
),
|
||||
op.batch_alter_table(
|
||||
"bill", recreate="always", table_kwargs={"sqlite_autoincrement": True}
|
||||
),
|
||||
op.batch_alter_table(
|
||||
"billowers", recreate="always", table_kwargs={"sqlite_autoincrement": True}
|
||||
),
|
||||
]
|
||||
|
||||
for batch_op in alter_table_batches:
|
||||
with batch_op:
|
||||
pass
|
||||
|
||||
|
||||
def downgrade():
|
||||
alter_table_batches = [
|
||||
op.batch_alter_table(
|
||||
"person", recreate="always", table_kwargs={"sqlite_autoincrement": False}
|
||||
),
|
||||
op.batch_alter_table(
|
||||
"bill", recreate="always", table_kwargs={"sqlite_autoincrement": False}
|
||||
),
|
||||
op.batch_alter_table(
|
||||
"billowers", recreate="always", table_kwargs={"sqlite_autoincrement": False}
|
||||
),
|
||||
]
|
||||
|
||||
for batch_op in alter_table_batches:
|
||||
with batch_op:
|
||||
pass
|
|
@ -345,6 +345,8 @@ class Person(db.Model):
|
|||
# Direct SQLAlchemy-Continuum to track changes to this model
|
||||
__versioned__ = {}
|
||||
|
||||
__table_args__ = {"sqlite_autoincrement": True}
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
project_id = db.Column(db.String(64), db.ForeignKey("project.id"))
|
||||
bills = db.relationship("Bill", backref="payer")
|
||||
|
@ -383,6 +385,7 @@ billowers = db.Table(
|
|||
"billowers",
|
||||
db.Column("bill_id", db.Integer, db.ForeignKey("bill.id"), primary_key=True),
|
||||
db.Column("person_id", db.Integer, db.ForeignKey("person.id"), primary_key=True),
|
||||
sqlite_autoincrement=True,
|
||||
)
|
||||
|
||||
|
||||
|
@ -412,6 +415,8 @@ class Bill(db.Model):
|
|||
# Direct SQLAlchemy-Continuum to track changes to this model
|
||||
__versioned__ = {}
|
||||
|
||||
__table_args__ = {"sqlite_autoincrement": True}
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
||||
payer_id = db.Column(db.Integer, db.ForeignKey("person.id"))
|
||||
|
|
Loading…
Reference in a new issue