Skip to content

Commit

Permalink
Configure SQLite to disable ID reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-Dickinson committed Apr 13, 2020
1 parent d008e88 commit e7848e3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions ihatemoney/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ def get(self, id, project=None):
# 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")
Expand Down Expand Up @@ -383,6 +385,7 @@ def __repr__(self):
"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,
)


Expand Down Expand Up @@ -412,6 +415,8 @@ def delete(self, project, id):
# 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"))
Expand Down

0 comments on commit e7848e3

Please sign in to comment.