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
1f5457df
Commit
1f5457df
authored
Sep 14, 2017
by
sim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Define trigger as ReplaceableObject to create triggers in alembic migrations
parent
9207690c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
4 deletions
+37
-4
alembic.py
gargantext/util/alembic.py
+37
-4
No files found.
gargantext/util/alembic.py
View file @
1f5457df
...
...
@@ -16,9 +16,9 @@ __all__ = ['ReplaceableObject']
class
ReplaceableObject
(
object
):
def
__init__
(
self
,
name
,
sqltext
):
def
__init__
(
self
,
name
,
*
args
):
self
.
name
=
name
self
.
sqltext
=
sqltext
self
.
args
=
args
class
ReversibleOp
(
MigrateOperation
):
...
...
@@ -85,11 +85,24 @@ class DropSPOp(ReversibleOp):
return
CreateSPOp
(
self
.
target
)
@
Operations
.
register_operation
(
"create_trigger"
,
"invoke_for_target"
)
@
Operations
.
register_operation
(
"replace_trigger"
,
"replace"
)
class
CreateTriggerOp
(
ReversibleOp
):
def
reverse
(
self
):
return
DropTriggerOp
(
self
.
target
)
@
Operations
.
register_operation
(
"drop_trigger"
,
"invoke_for_target"
)
class
DropTriggerOp
(
ReversibleOp
):
def
reverse
(
self
):
return
CreateTriggerOp
(
self
.
target
)
@
Operations
.
implementation_for
(
CreateViewOp
)
def
create_view
(
operations
,
operation
):
operations
.
execute
(
"CREATE VIEW
%
s AS
%
s"
%
(
operation
.
target
.
name
,
operation
.
target
.
sqltext
operation
.
target
.
args
[
0
]
))
...
...
@@ -102,7 +115,7 @@ def drop_view(operations, operation):
def
create_sp
(
operations
,
operation
):
operations
.
execute
(
"CREATE FUNCTION
%
s
%
s"
%
(
operation
.
target
.
name
,
operation
.
target
.
sqltext
operation
.
target
.
name
,
operation
.
target
.
args
[
0
]
)
)
...
...
@@ -110,3 +123,23 @@ def create_sp(operations, operation):
@
Operations
.
implementation_for
(
DropSPOp
)
def
drop_sp
(
operations
,
operation
):
operations
.
execute
(
"DROP FUNCTION
%
s"
%
operation
.
target
.
name
)
@
Operations
.
implementation_for
(
CreateTriggerOp
)
def
create_trigger
(
operations
,
operation
):
args
=
operation
.
target
.
args
operations
.
execute
(
"CREATE TRIGGER
%
s
%
s ON
%
s
%
s"
%
(
operation
.
target
.
name
,
args
[
0
],
args
[
1
],
args
[
2
]
)
)
@
Operations
.
implementation_for
(
DropTriggerOp
)
def
drop_trigger
(
operations
,
operation
):
operations
.
execute
(
"DROP TRIGGER
%
s ON
%
s"
%
(
operation
.
target
.
name
,
operation
.
target
.
args
[
1
]
)
)
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