Skip to content

Commit

Permalink
* **Fix:** As usual after a new release that changes database schema,…
Browse files Browse the repository at this point in the history
… fixed the corresponding Alembic revision (92257ba439e1).
  • Loading branch information
eoyilmaz committed Jul 28, 2016
1 parent 6c452db commit 447441a
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Expand Up @@ -2,6 +2,12 @@
Stalker Changes
===============

0.2.16.1
========

* **Fix:** As usual after a new release that changes database schema, fixed the
corresponding Alembic revision (92257ba439e1).

0.2.16
======

Expand Down
99 changes: 93 additions & 6 deletions alembic/versions/92257ba439e1_budget_is_now_statusable.py
Expand Up @@ -17,11 +17,11 @@
def upgrade():
op.add_column(
'Budgets',
sa.Column('status_id', sa.Integer(), nullable=False)
sa.Column('status_id', sa.Integer(), nullable=True)
)
op.add_column(
'Budgets',
sa.Column('status_list_id', sa.Integer(), nullable=False)
sa.Column('status_list_id', sa.Integer(), nullable=True)
)
op.create_foreign_key(
None, 'Budgets', 'Statuses', ['status_id'], ['id']
Expand All @@ -30,9 +30,96 @@ def upgrade():
None, 'Budgets', 'StatusLists', ['status_list_id'], ['id']
)

# create a dummy status list for budgets
op.execute(
"""insert into "SimpleEntities" (name, entity_type)
values ('Dummy Budget StatusList', 'StatusList');
insert into "Entities" (id)
select
"SimpleEntities".id
from "SimpleEntities"
where "SimpleEntities".entity_type = 'StatusList' and
"SimpleEntities".name = 'Dummy Budget StatusList'
;
insert into "StatusLists" (id, target_entity_type)
select
"SimpleEntities".id,
'Budget'
from "SimpleEntities"
where "SimpleEntities".entity_type = 'StatusList' and
"SimpleEntities".name = 'Dummy Budget StatusList'
;
insert into "StatusList_Statuses"
select
"SimpleEntities".id,
"Statuses".id
from "SimpleEntities", "Statuses"
where "SimpleEntities".name = 'Dummy Budget StatusList'
order by "Statuses".id
limit 1
;
update "Budgets"
set status_id = (
select "Statuses".id
from "Statuses"
order by "Statuses".id limit 1
)
;
update "Budgets"
set status_list_id = (
select "SimpleEntities".id
from "SimpleEntities"
where "SimpleEntities".name = 'Dummy Budget StatusList'
)
;
"""
)
# now alter column to be non nullable
op.alter_column('Budgets', 'status_id', nullable=False)
op.alter_column('Budgets', 'status_list_id', nullable=False)


def downgrade():
op.drop_constraint(None, 'Budgets', type_='foreignkey')
op.drop_constraint(None, 'Budgets', type_='foreignkey')
op.drop_column('Budgets', 'status_list_id')
op.drop_column('Budgets', 'status_id')
op.execute("""
ALTER TABLE public."Budgets" DROP CONSTRAINT "Budgets_status_id_fkey";
ALTER TABLE public."Budgets" DROP CONSTRAINT "Budgets_status_list_id_fkey";
ALTER TABLE public."Budgets" DROP COLUMN status_id;
ALTER TABLE public."Budgets" DROP COLUMN status_list_id;
""")

# remove 'Dummy Budget StatusList' if it exists
op.execute(
"""
delete
from "StatusList_Statuses"
where "StatusList_Statuses".status_list_id = (
select
id
from "SimpleEntities"
where "SimpleEntities".name = 'Dummy Budget StatusList'
)
;
delete
from "StatusLists"
where "StatusLists".id = (
select
id
from "SimpleEntities"
where "SimpleEntities".name = 'Dummy Budget StatusList'
)
;
delete
from "Entities"
where "Entities".id = (
select
id
from "SimpleEntities"
where "SimpleEntities".name = 'Dummy Budget StatusList'
)
;
delete
from "SimpleEntities"
where "SimpleEntities".name = 'Dummy Budget StatusList'
;
"""
)
2 changes: 1 addition & 1 deletion stalker/__init__.py
Expand Up @@ -25,7 +25,7 @@

import sys

__version__ = '0.2.16'
__version__ = '0.2.16.1'


__string_types__ = []
Expand Down

0 comments on commit 447441a

Please sign in to comment.