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
7e9030c9
Commit
7e9030c9
authored
Jun 09, 2016
by
delanoe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT] Script de migration.
parent
da72781a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
94 additions
and
3 deletions
+94
-3
migration.py
gargantext/models/migration.py
+94
-3
No files found.
gargantext/models/migration.py
View file @
7e9030c9
from
gargantext.util.db
import
*
from
gargantext.util.files
import
upload
from
gargantext.constants
import
*
from
gargantext.util.toolchain.main
import
parse_extract_indexhyperdata
from
datetime
import
datetime
from
.users
import
User
from
.nodes
import
Node
#__all__ = ['Node', 'NodeType', 'Language']
class
NodeType_v2
(
Base
):
__table_args__
=
{
'extend_existing'
:
True
}
__tablename__
=
'node_nodetype'
...
...
@@ -38,6 +40,22 @@ class Node_v2(Base):
hyperdata
=
Column
(
JSONB
,
default
=
dict
)
class
ResourceType
(
Base
):
__table_args__
=
{
'extend_existing'
:
True
}
__tablename__
=
'node_resourcetype'
id
=
Column
(
Integer
,
primary_key
=
True
)
name
=
Column
(
String
(
255
))
class
NodeResource
(
Base
):
__table_args__
=
{
'extend_existing'
:
True
}
__tablename__
=
'node_node_resource'
id
=
Column
(
Integer
,
primary_key
=
True
)
node_id
=
Column
(
ForeignKey
(
Node_v2
.
id
))
resource_id
=
Column
(
ForeignKey
(
ResourceType
.
id
))
parsed
=
Column
(
Boolean
)
def
nodes_list
(
user_id
,
nodetype
,
parent_id
=
None
,
count
=
False
):
"""
nodes_list :: Int -> String -> Maybe Int -> Maybe Bool -> [(Int, String)]
...
...
@@ -69,7 +87,80 @@ def nodes_tree(user_id):
)
if
count
>
1
:
print
(
"|-
%
d
%
s"
%
(
corpus_id
,
corpus_name
))
print
(
" |-
%
s docs"
%
count
)
print
(
"|__
%
d
%
s"
%
(
corpus_id
,
corpus_name
))
print
(
" |___
%
s docs"
%
count
)
def
copy_nodes
(
node_id
,
to_parent_id
=
None
,
enabled
=
[
'PROJECT'
,
'CORPUS'
,
'DOCUMENT'
]):
node
=
session
.
query
(
Node_v2
)
.
filter
(
Node_v2
.
id
==
node_id
)
.
first
()
nodetype
=
session
.
query
(
NodeType_v2
)
.
filter
(
NodeType_v2
.
id
==
node
.
type_id
)
.
first
()
resource
=
(
session
.
query
(
ResourceType
)
.
join
(
NodeResource
,
NodeResource
.
resource_id
==
ResourceType
.
id
)
.
filter
(
NodeResource
.
node_id
==
node
.
id
)
.
first
()
)
nodetype_proj_id
=
session
.
query
(
NodeType_v2
.
id
)
.
filter
(
NodeType_v2
.
name
==
'Project'
)
.
first
()
nodetype_corp_id
=
session
.
query
(
NodeType_v2
.
id
)
.
filter
(
NodeType_v2
.
name
==
'Corpus'
)
.
first
()
nodetype_docu_id
=
session
.
query
(
NodeType_v2
.
id
)
.
filter
(
NodeType_v2
.
name
==
'Document'
)
.
first
()
typename
=
nodetype
.
name
.
upper
()
# Import a project:
# new_project = Node(
# user_id = user.id,
# typename = 'PROJECT',
# name = name,
# )
# session.add(new_project)
# session.commit()
if
typename
in
enabled
:
parent_node
=
session
.
query
(
Node
)
.
filter
(
Node
.
id
==
to_parent_id
)
.
first
()
if
parent_node
is
not
None
:
corpus
=
parent_node
.
add_child
(
name
=
node
.
name
,
typename
=
typename
)
corpus
.
hyperdata
[
'languages'
]
=
{
'fr'
:
100
}
try
:
corpus
.
add_resource
(
type
=
resourcetype
(
resource
.
name
)
)
except
:
corpus
.
add_resource
(
type
=
resourcetype
(
'Europress (French)'
)
)
session
.
add
(
corpus
)
session
.
commit
()
print
(
"
%
s copied"
%
corpus
.
name
)
nodes
=
(
session
.
query
(
Node_v2
)
.
filter
(
Node_v2
.
parent_id
==
node
.
id
)
.
filter
(
Node_v2
.
type_id
==
nodetype_docu_id
)
.
all
()
)
for
n
in
nodes
:
print
(
n
.
name
)
doc
=
corpus
.
add_child
(
name
=
n
.
name
,
typename
=
"DOCUMENT"
,
hyperdata
=
n
.
hyperdata
)
session
.
add
(
doc
)
session
.
commit
()
# else:
# print("%d is None" % parent_id)
else
:
print
(
'
%
s is not enabled'
%
typename
)
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