[WIP] On create of notification. Upsert record for template stats

recording usages of template by day.
This commit is contained in:
Adam Shimali
2016-03-31 15:57:50 +01:00
parent 7ec1f31bab
commit ca9c886c3e
6 changed files with 289 additions and 28 deletions

View File

@@ -0,0 +1,42 @@
"""empty message
Revision ID: 0044_add_template_stats
Revises: 0043_add_view_activity
Create Date: 2016-03-31 12:05:19.630792
"""
# revision identifiers, used by Alembic.
revision = '0044_add_template_stats'
down_revision = '0043_add_view_activity'
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
def upgrade():
### commands auto generated by Alembic - please adjust! ###
op.create_table('template_statistics',
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('service_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.Column('template_id', sa.BigInteger(), nullable=False),
sa.Column('usage_count', sa.BigInteger(), nullable=False),
sa.Column('day', sa.Date(), nullable=False),
sa.ForeignKeyConstraint(['service_id'], ['services.id'], ),
sa.ForeignKeyConstraint(['template_id'], ['templates.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_template_statistics_day'), 'template_statistics', ['day'], unique=False)
op.create_index(op.f('ix_template_statistics_service_id'), 'template_statistics', ['service_id'], unique=False)
op.create_index(op.f('ix_template_statistics_template_id'), 'template_statistics', ['template_id'], unique=False)
### end Alembic commands ###
def downgrade():
### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_template_statistics_template_id'), table_name='template_statistics')
op.drop_index(op.f('ix_template_statistics_service_id'), table_name='template_statistics')
op.drop_index(op.f('ix_template_statistics_day'), table_name='template_statistics')
op.drop_table('template_statistics')
### end Alembic commands ###