Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
humanities
gargantext
Commits
079257f4
Commit
079257f4
authored
Oct 09, 2017
by
sim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DB] Alembic: factorize ReversibleOp
parent
382d518a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
43 deletions
+20
-43
alembic.py
gargantext/util/alembic.py
+20
-43
No files found.
gargantext/util/alembic.py
View file @
079257f4
...
@@ -7,6 +7,8 @@ the name of "ReplaceableObject" class.
...
@@ -7,6 +7,8 @@ the name of "ReplaceableObject" class.
This recipe is directly borrowed from Alembic documentation, see
This recipe is directly borrowed from Alembic documentation, see
http://alembic.zzzcomputing.com/en/latest/cookbook.html#replaceable-objects
http://alembic.zzzcomputing.com/en/latest/cookbook.html#replaceable-objects
**2017-10-09** ReversibleOp.define has been added to reduce boilerplate code.
"""
"""
from
alembic.operations
import
Operations
,
MigrateOperation
from
alembic.operations
import
Operations
,
MigrateOperation
...
@@ -58,57 +60,32 @@ class ReversibleOp(MigrateOperation):
...
@@ -58,57 +60,32 @@ class ReversibleOp(MigrateOperation):
operations
.
invoke
(
drop_old
)
operations
.
invoke
(
drop_old
)
operations
.
invoke
(
create_new
)
operations
.
invoke
(
create_new
)
@
classmethod
def
define
(
cls
,
name
,
cname
=
None
,
register
=
Operations
.
register_operation
):
def
create
(
self
):
return
CreateOp
(
self
.
target
)
@
Operations
.
register_operation
(
"create_view"
,
"invoke_for_target"
)
def
drop
(
self
):
@
Operations
.
register_operation
(
"replace_view"
,
"replace"
)
return
DropOp
(
self
.
target
)
class
CreateViewOp
(
ReversibleOp
):
def
reverse
(
self
):
return
DropViewOp
(
self
.
target
)
@
Operations
.
register_operation
(
"drop_view"
,
"invoke_for_target"
)
class
DropViewOp
(
ReversibleOp
):
def
reverse
(
self
):
return
CreateViewOp
(
self
.
target
)
@
Operations
.
register_operation
(
"create_sp"
,
"invoke_for_target"
)
@
Operations
.
register_operation
(
"replace_sp"
,
"replace"
)
class
CreateSPOp
(
ReversibleOp
):
def
reverse
(
self
):
return
DropSPOp
(
self
.
target
)
@
Operations
.
register_operation
(
"drop_sp"
,
"invoke_for_target"
)
class
DropSPOp
(
ReversibleOp
):
def
reverse
(
self
):
return
CreateSPOp
(
self
.
target
)
@
Operations
.
register_operation
(
"create_trigger"
,
"invoke_for_target"
)
name
=
name
.
lower
()
@
Operations
.
register_operation
(
"replace_trigger"
,
"replace"
)
cname
=
cname
or
name
.
capitalize
()
class
CreateTriggerOp
(
ReversibleOp
):
def
reverse
(
self
):
return
DropTriggerOp
(
self
.
target
)
CreateOp
=
type
(
'Create
%
sOp'
%
cname
,
(
ReversibleOp
,),
{
'reverse'
:
drop
})
DropOp
=
type
(
'Drop
%
sOp'
%
cname
,
(
ReversibleOp
,),
{
'reverse'
:
create
})
@
Operations
.
register_operation
(
"drop_trigger"
,
"invoke_for_target"
)
CreateOp
=
register
(
'create_'
+
name
,
'invoke_for_target'
)(
CreateOp
)
class
DropTriggerOp
(
ReversibleOp
):
CreateOp
=
register
(
'replace_'
+
name
,
'replace'
)(
CreateOp
)
def
reverse
(
self
):
return
CreateTriggerOp
(
self
.
target
)
DropOp
=
register
(
'drop_'
+
name
,
'invoke_for_target'
)(
DropOp
)
@
Operations
.
register_operation
(
"create_role"
,
"invoke_for_target"
)
return
(
CreateOp
,
DropOp
)
@
Operations
.
register_operation
(
"replace_sp"
,
"replace"
)
class
CreateRoleOp
(
ReversibleOp
):
def
reverse
(
self
):
return
DropRoleOp
(
self
.
target
)
@
Operations
.
register_operation
(
"drop_role"
,
"invoke_for_target"
)
CreateViewOp
,
DropViewOp
=
ReversibleOp
.
define
(
'view'
)
class
DropRoleOp
(
ReversibleOp
):
CreateRoleOp
,
DropRoleOp
=
ReversibleOp
.
define
(
'role'
)
def
reverse
(
self
):
CreateSPOp
,
DropSPOp
=
ReversibleOp
.
define
(
'sp'
,
'SP'
)
return
CreateRoleOp
(
self
.
target
)
CreateTriggerOp
,
DropTriggerOp
=
ReversibleOp
.
define
(
'trigger'
)
@
Operations
.
implementation_for
(
CreateViewOp
)
@
Operations
.
implementation_for
(
CreateViewOp
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment