-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tags can now be added in the description of a bill, using a hashtag symbol (`#tagname`). There is no way to "manage" the tags, for simplicity, they are part of the "what" field, and are parsed via a regular expression. Statistics have been updated to include tags per month. Under the hood, a new `tag` table has been added.
- Loading branch information
Showing
4 changed files
with
132 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
ihatemoney/migrations/versions/d53fe61e5521_add_a_tags_table.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
"""Add a tags table | ||
Revision ID: d53fe61e5521 | ||
Revises: 7a9b38559992 | ||
Create Date: 2024-05-16 00:32:19.566457 | ||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'd53fe61e5521' | ||
down_revision = '7a9b38559992' | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table('billtags_version', | ||
sa.Column('bill_id', sa.Integer(), autoincrement=False, nullable=False), | ||
sa.Column('tag_id', sa.Integer(), autoincrement=False, nullable=False), | ||
sa.Column('transaction_id', sa.BigInteger(), autoincrement=False, nullable=False), | ||
sa.Column('end_transaction_id', sa.BigInteger(), nullable=True), | ||
sa.Column('operation_type', sa.SmallInteger(), nullable=False), | ||
sa.PrimaryKeyConstraint('bill_id', 'tag_id', 'transaction_id') | ||
) | ||
with op.batch_alter_table('billtags_version', schema=None) as batch_op: | ||
batch_op.create_index(batch_op.f('ix_billtags_version_end_transaction_id'), ['end_transaction_id'], unique=False) | ||
batch_op.create_index(batch_op.f('ix_billtags_version_operation_type'), ['operation_type'], unique=False) | ||
batch_op.create_index(batch_op.f('ix_billtags_version_transaction_id'), ['transaction_id'], unique=False) | ||
|
||
op.create_table('tag', | ||
sa.Column('id', sa.Integer(), nullable=False), | ||
sa.Column('project_id', sa.String(length=64), nullable=True), | ||
sa.Column('name', sa.UnicodeText(), nullable=True), | ||
sa.ForeignKeyConstraint(['project_id'], ['project.id'], ), | ||
sa.PrimaryKeyConstraint('id'), | ||
sqlite_autoincrement=True | ||
) | ||
op.create_table('billtags', | ||
sa.Column('bill_id', sa.Integer(), nullable=False), | ||
sa.Column('tag_id', sa.Integer(), nullable=False), | ||
sa.ForeignKeyConstraint(['bill_id'], ['bill.id'], ), | ||
sa.ForeignKeyConstraint(['tag_id'], ['tag.id'], ), | ||
sa.PrimaryKeyConstraint('bill_id', 'tag_id'), | ||
sqlite_autoincrement=True | ||
) | ||
with op.batch_alter_table('bill_version', schema=None) as batch_op: | ||
batch_op.alter_column('bill_type', | ||
existing_type=sa.TEXT(), | ||
type_=sa.Enum('EXPENSE', 'REIMBURSEMENT', name='billtype'), | ||
existing_nullable=True, | ||
autoincrement=False) | ||
|
||
with op.batch_alter_table('billowers', schema=None) as batch_op: | ||
batch_op.alter_column('bill_id', | ||
existing_type=sa.INTEGER(), | ||
nullable=False) | ||
batch_op.alter_column('person_id', | ||
existing_type=sa.INTEGER(), | ||
nullable=False) | ||
|
||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
with op.batch_alter_table('billowers', schema=None) as batch_op: | ||
batch_op.alter_column('person_id', | ||
existing_type=sa.INTEGER(), | ||
nullable=True) | ||
batch_op.alter_column('bill_id', | ||
existing_type=sa.INTEGER(), | ||
nullable=True) | ||
|
||
with op.batch_alter_table('bill_version', schema=None) as batch_op: | ||
batch_op.alter_column('bill_type', | ||
existing_type=sa.Enum('EXPENSE', 'REIMBURSEMENT', name='billtype'), | ||
type_=sa.TEXT(), | ||
existing_nullable=True, | ||
autoincrement=False) | ||
|
||
op.drop_table('billtags') | ||
op.drop_table('tag') | ||
with op.batch_alter_table('billtags_version', schema=None) as batch_op: | ||
batch_op.drop_index(batch_op.f('ix_billtags_version_transaction_id')) | ||
batch_op.drop_index(batch_op.f('ix_billtags_version_operation_type')) | ||
batch_op.drop_index(batch_op.f('ix_billtags_version_end_transaction_id')) | ||
|
||
op.drop_table('billtags_version') | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters