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
7110ae5b
Commit
7110ae5b
authored
Mar 29, 2018
by
sim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migration: rename typename, date, hyperdata of Node to type, created and data
parent
babbc0c9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
91 additions
and
0 deletions
+91
-0
8fced8397139_rename_typename_date_hyperdata_of_nodes_.py
.../8fced8397139_rename_typename_date_hyperdata_of_nodes_.py
+91
-0
No files found.
alembic/versions/8fced8397139_rename_typename_date_hyperdata_of_nodes_.py
0 → 100644
View file @
7110ae5b
"""Rename typename, date, hyperdata of nodes to type, created and data
Revision ID: 8fced8397139
Revises: 492ab1373f8d
Create Date: 2018-03-29 14:08:45.321752
"""
from
alembic
import
op
import
sqlalchemy
as
sa
from
sqlalchemy.dialects
import
postgresql
from
gargantext.utils.alembic
import
ReplaceableObject
# revision identifiers, used by Alembic.
revision
=
'8fced8397139'
down_revision
=
'492ab1373f8d'
branch_labels
=
None
depends_on
=
None
title_abstract_update_trigger
=
ReplaceableObject
(
'title_abstract_update_trigger()'
,
"""
RETURNS trigger AS $$
begin
new.title_abstract := to_tsvector('english', (new.data ->> 'title') || ' ' || (new.data ->> 'abstract'));
return new;
end
$$ LANGUAGE plpgsql;
"""
)
title_abstract_insert
=
ReplaceableObject
(
'title_abstract_insert'
,
'AFTER INSERT'
,
'nodes'
,
"""FOR EACH ROW
WHEN (NEW.data::text <> '{}'::text)
EXECUTE PROCEDURE title_abstract_update_trigger()"""
)
title_abstract_update
=
ReplaceableObject
(
'title_abstract_update'
,
'AFTER UPDATE OF data'
,
'nodes'
,
"""FOR EACH ROW
WHEN ((OLD.data ->> 'title', OLD.data ->> 'abstract')
IS DISTINCT FROM
(NEW.data ->> 'title', NEW.data ->> 'abstract'))
EXECUTE PROCEDURE title_abstract_update_trigger()"""
)
def
upgrade
():
op
.
drop_index
(
'ix_nodes_typename'
,
table_name
=
'nodes'
)
op
.
drop_index
(
'nodes_hyperdata_idx'
,
table_name
=
'nodes'
)
op
.
drop_index
(
'nodes_user_id_typename_parent_id_idx'
,
table_name
=
'nodes'
)
op
.
alter_column
(
'nodes'
,
'typename'
,
new_column_name
=
'type'
)
op
.
alter_column
(
'nodes'
,
'date'
,
new_column_name
=
'created'
)
op
.
alter_column
(
'nodes'
,
'hyperdata'
,
new_column_name
=
'data'
)
op
.
create_index
(
op
.
f
(
'ix_nodes_type'
),
'nodes'
,
[
'type'
],
unique
=
False
)
op
.
create_index
(
'nodes_data_idx'
,
'nodes'
,
[
'data'
],
unique
=
False
,
postgresql_using
=
'gin'
)
op
.
create_index
(
'nodes_user_id_type_parent_id_idx'
,
'nodes'
,
[
'user_id'
,
'type'
,
'parent_id'
],
unique
=
False
)
op
.
replace_sp
(
title_abstract_update_trigger
,
replaces
=
"1fb4405b59e1.title_abstract_update_trigger"
)
op
.
create_trigger
(
title_abstract_update
)
op
.
create_trigger
(
title_abstract_insert
)
# Manually re-build index
op
.
execute
(
"UPDATE nodes SET title_abstract = to_tsvector('english', (data ->> 'title') || ' ' || (data ->> 'abstract')) WHERE type=4"
)
def
downgrade
():
op
.
drop_index
(
'nodes_user_id_type_parent_id_idx'
,
table_name
=
'nodes'
)
op
.
drop_index
(
'nodes_data_idx'
,
table_name
=
'nodes'
)
op
.
drop_index
(
op
.
f
(
'ix_nodes_type'
),
table_name
=
'nodes'
)
op
.
alter_column
(
'nodes'
,
'type'
,
new_column_name
=
'typename'
)
op
.
alter_column
(
'nodes'
,
'created'
,
new_column_name
=
'date'
)
op
.
alter_column
(
'nodes'
,
'data'
,
new_column_name
=
'hyperdata'
)
op
.
create_index
(
'nodes_user_id_typename_parent_id_idx'
,
'nodes'
,
[
'user_id'
,
'typename'
,
'parent_id'
],
unique
=
False
)
op
.
create_index
(
'nodes_hyperdata_idx'
,
'nodes'
,
[
'hyperdata'
],
unique
=
False
,
postgresql_using
=
'gin'
)
op
.
create_index
(
'ix_nodes_typename'
,
'nodes'
,
[
'typename'
],
unique
=
False
)
op
.
replace_sp
(
title_abstract_update_trigger
,
replace_with
=
"1fb4405b59e1.title_abstract_update_trigger"
)
op
.
create_trigger
(
"159a5154362b.title_abstract_update"
)
op
.
create_trigger
(
"159a5154362b.title_abstract_insert"
)
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