Skip to content

Commit

Permalink
* **Fix:** Fixed alembic revision (f2005d1fbadc), it will now drop an…
Browse files Browse the repository at this point in the history
…y existing constraints before re-creating them. And the downgrade function will not remove the constraints.
  • Loading branch information
eoyilmaz committed Jun 28, 2016
1 parent 2491890 commit 864c2db
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 97 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
Stalker Changes
===============

0.2.15.1
========

* **Fix:** Fixed alembic revision (f2005d1fbadc), it will now drop any existing
constraints before re-creating them. And the downgrade function will not
remove the constraints.

0.2.15
======

Expand Down
201 changes: 105 additions & 96 deletions alembic/versions/f2005d1fbadc_added_projectclients.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,54 @@ def upgrade():
"""
)

# These were coming up in every revision, and I was cleaning them every
# time, so I'm leaving them in this one now
op.create_foreign_key(None, 'BudgetEntries', 'Goods', ['good_id'], ['id'])
op.create_foreign_key(None, 'Budgets', 'Budgets', ['parent_id'], ['id'])
op.create_foreign_key(None, 'Dailies', 'Projects', ['project_id'], ['id'])
op.create_foreign_key(None, 'Department_Users', 'Roles', ['rid'], ['id'])
op.create_foreign_key(None, 'Pages', 'Projects', ['project_id'], ['id'])
op.create_foreign_key(None, 'Project_Users', 'Roles', ['rid'], ['id'])
# create missing constraints if any
op.execute("""
ALTER TABLE "BudgetEntries" DROP CONSTRAINT IF EXISTS "BudgetEntries_good_id_fkey";
ALTER TABLE "BudgetEntries"
ADD CONSTRAINT "BudgetEntries_good_id_fkey" FOREIGN KEY (good_id)
REFERENCES public."Goods" (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
""")

op.execute("""
ALTER TABLE "Budgets" DROP CONSTRAINT IF EXISTS "Budgets_parent_id_fkey";
ALTER TABLE public."Budgets"
ADD CONSTRAINT "Budgets_parent_id_fkey" FOREIGN KEY (parent_id)
REFERENCES public."Budgets" (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
""")

op.execute("""
ALTER TABLE "Dailies" DROP CONSTRAINT IF EXISTS "Dailies_project_id_fkey";
ALTER TABLE public."Dailies"
ADD CONSTRAINT "Dailies_project_id_fkey" FOREIGN KEY (project_id)
REFERENCES public."Projects" (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
""")

op.execute("""
ALTER TABLE "Department_Users" DROP CONSTRAINT IF EXISTS "Department_Users_rid_fkey";
ALTER TABLE public."Department_Users"
ADD CONSTRAINT "Department_Users_rid_fkey" FOREIGN KEY (rid)
REFERENCES public."Roles" (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
""")

op.execute("""
ALTER TABLE "Pages" DROP CONSTRAINT IF EXISTS "Pages_project_id_fkey";
ALTER TABLE public."Pages"
ADD CONSTRAINT "Pages_project_id_fkey" FOREIGN KEY (project_id)
REFERENCES public."Projects" (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
""")

op.execute("""
ALTER TABLE "Project_Users" DROP CONSTRAINT IF EXISTS "Project_Users_rid_fkey";
ALTER TABLE public."Project_Users"
ADD CONSTRAINT "Project_Users_rid_fkey" FOREIGN KEY (rid)
REFERENCES public."Roles" (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
""")

op.drop_constraint(
u'Projects_client_id_fkey',
Expand All @@ -52,64 +92,75 @@ def upgrade():
)
op.drop_column(u'Projects', 'client_id')

op.create_foreign_key(None, 'Scenes', 'Projects', ['project_id'], ['id'])
op.create_foreign_key(
'xu',
'SimpleEntities',
'Users',
['updated_by_id'],
['id'],
use_alter=True
)
op.create_foreign_key(
'z',
'SimpleEntities',
'Links',
['thumbnail_id'],
['id'],
use_alter=True
)
op.create_foreign_key(
'y',
'SimpleEntities',
'Types',
['type_id'],
['id'],
use_alter=True
)
op.create_foreign_key(
None,
'Studios',
'Users',
['last_scheduled_by_id'],
['id']
)
op.create_foreign_key(
None,
'Studios',
'Users',
['is_scheduling_by_id'],
['id']
)
op.execute("""
ALTER TABLE "Scenes" DROP CONSTRAINT IF EXISTS "Scenes_project_id_fkey";
ALTER TABLE public."Scenes"
ADD CONSTRAINT "Scenes_project_id_fkey" FOREIGN KEY (project_id)
REFERENCES public."Projects" (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
""")

op.execute("""
ALTER TABLE "SimpleEntities" DROP CONSTRAINT IF EXISTS xu;
ALTER TABLE "SimpleEntities"
ADD CONSTRAINT xu FOREIGN KEY (updated_by_id)
REFERENCES public."Users" (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
""")

op.execute("""
ALTER TABLE "SimpleEntities" DROP CONSTRAINT IF EXISTS z;
ALTER TABLE public."SimpleEntities"
ADD CONSTRAINT z FOREIGN KEY (thumbnail_id)
REFERENCES public."Links" (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
""")

op.execute("""
ALTER TABLE "SimpleEntities" DROP CONSTRAINT IF EXISTS y;
ALTER TABLE public."SimpleEntities"
ADD CONSTRAINT y FOREIGN KEY (type_id)
REFERENCES public."Types" (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
""")

op.execute("""
ALTER TABLE "Studios" DROP CONSTRAINT IF EXISTS "Studios_last_scheduled_by_id_fkey";
ALTER TABLE "Studios"
ADD CONSTRAINT "Studios_last_scheduled_by_id_fkey" FOREIGN KEY (last_scheduled_by_id)
REFERENCES public."Users" (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
""")

op.execute("""
ALTER TABLE "Studios" DROP CONSTRAINT IF EXISTS "Studios_is_scheduling_by_id_fkey";
ALTER TABLE "Studios"
ADD CONSTRAINT "Studios_is_scheduling_by_id_fkey" FOREIGN KEY (is_scheduling_by_id)
REFERENCES public."Users" (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
""")

op.alter_column(
u'Task_Dependencies',
'gap_timing',
existing_type=postgresql.DOUBLE_PRECISION(precision=53),
nullable=True
)

op.alter_column(
u'Task_Dependencies',
'gap_unit',
existing_type=postgresql.VARCHAR(length=256),
nullable=True
)
op.create_foreign_key(
None,
'Tasks',
'Goods',
['good_id'],
['id']
)

op.execute("""
ALTER TABLE "Tasks" DROP CONSTRAINT IF EXISTS "Tasks_good_id_fkey";
ALTER TABLE public."Tasks"
ADD CONSTRAINT "Tasks_good_id_fkey" FOREIGN KEY (good_id)
REFERENCES public."Goods" (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION;
""")


def downgrade():
Expand All @@ -127,27 +178,6 @@ def downgrade():
nullable=True
)

op.execute(
'ALTER TABLE "Studios" '
'DROP CONSTRAINT "Studios_is_scheduling_by_id_fkey"'
)
op.execute(
'ALTER TABLE "Studios" '
'DROP CONSTRAINT "Studios_last_scheduled_by_id_fkey"'
)
op.execute(
'ALTER TABLE "SimpleEntities" DROP CONSTRAINT y'
)
op.execute(
'ALTER TABLE "SimpleEntities" DROP CONSTRAINT z'
)
op.execute(
'ALTER TABLE "SimpleEntities" DROP CONSTRAINT xu'
)
op.execute(
'ALTER TABLE "Scenes" DROP CONSTRAINT "Scenes_project_id_fkey"'
)

op.add_column(
u'Projects',
sa.Column(
Expand All @@ -165,27 +195,6 @@ def downgrade():
['id']
)

op.execute(
'ALTER TABLE "Project_Users" DROP CONSTRAINT "Project_Users_rid_fkey"'
)
op.execute(
'ALTER TABLE "Pages" DROP CONSTRAINT "Pages_project_id_fkey"'
)
op.execute(
'ALTER TABLE "Department_Users" '
'DROP CONSTRAINT "Department_Users_rid_fkey"'
)
op.execute(
'ALTER TABLE "Dailies" DROP CONSTRAINT "Dailies_project_id_fkey"'
)
op.execute(
'ALTER TABLE "Budgets" DROP CONSTRAINT "Budgets_parent_id_fkey"'
)
op.execute(
'ALTER TABLE "BudgetEntries" '
'DROP CONSTRAINT "BudgetEntries_good_id_fkey"'
)

# before dropping the Project_Clients, add the first client as the
# Project.client_id
op.execute(
Expand Down
2 changes: 1 addition & 1 deletion stalker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import sys

__version__ = '0.2.15'
__version__ = '0.2.15.1'


__string_types__ = []
Expand Down

0 comments on commit 864c2db

Please sign in to comment.