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
88bcf569
Commit
88bcf569
authored
May 31, 2016
by
delanoe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT] Migration scripts: nodes from Gargantext v2.
parent
382c2773
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
0 deletions
+75
-0
migration.py
gargantext/models/migration.py
+75
-0
No files found.
gargantext/models/migration.py
0 → 100644
View file @
88bcf569
from
gargantext.util.db
import
*
from
gargantext.util.files
import
upload
from
gargantext.constants
import
*
from
datetime
import
datetime
from
.users
import
User
#__all__ = ['Node', 'NodeType', 'Language']
class
NodeType_v2
(
Base
):
__table_args__
=
{
'extend_existing'
:
True
}
__tablename__
=
'node_nodetype'
id
=
Column
(
Integer
,
primary_key
=
True
)
name
=
Column
(
String
(
255
))
class
Language_v2
(
Base
):
__table_args__
=
{
'extend_existing'
:
True
}
__tablename__
=
'node_language'
id
=
Column
(
Integer
,
primary_key
=
True
)
iso2
=
Column
(
String
(
2
))
iso3
=
Column
(
String
(
3
))
fullname
=
Column
(
String
(
255
))
implemented
=
Column
(
Boolean
)
class
Node_v2
(
Base
):
__table_args__
=
{
'extend_existing'
:
True
}
__tablename__
=
'node_node'
id
=
Column
(
Integer
,
primary_key
=
True
)
parent_id
=
Column
(
Integer
,
ForeignKey
(
'node_node.id'
))
user_id
=
Column
(
Integer
,
ForeignKey
(
User
.
id
))
type_id
=
Column
(
ForeignKey
(
NodeType_v2
.
id
))
name
=
Column
(
String
(
255
))
language_id
=
Column
(
Integer
,
ForeignKey
(
Language_v2
.
id
))
date
=
Column
(
DateTime
(),
default
=
datetime
.
now
)
hyperdata
=
Column
(
JSONB
,
default
=
dict
)
def
nodes_list
(
user_id
,
nodetype
,
parent_id
=
None
,
count
=
False
):
"""
nodes_list :: Int -> String -> Maybe Int -> Maybe Bool -> [(Int, String)]
"""
nodes
=
(
session
.
query
(
Node_v2
.
id
,
Node_v2
.
name
)
.
join
(
NodeType_v2
,
NodeType_v2
.
id
==
Node_v2
.
type_id
)
.
filter
(
NodeType_v2
.
name
==
nodetype
)
)
if
parent_id
is
not
None
:
nodes
=
nodes
.
filter
(
Node_v2
.
parent_id
==
parent_id
)
if
count
is
True
:
return
nodes
.
count
()
else
:
return
nodes
.
all
()
def
nodes_tree
(
user_id
):
"""
nodes_tree :: Int -> Tree Nodes
"""
for
project_id
,
project_name
in
nodes_list
(
user_id
,
'Project'
):
print
(
"* Project (
%
d,
%
s)"
%
(
project_id
,
project_name
))
for
corpus_id
,
corpus_name
in
nodes_list
(
user_id
,
'Corpus'
,
parent_id
=
project_id
):
count
=
nodes_list
(
user_id
,
'Document'
,
parent_id
=
corpus_id
,
count
=
True
)
if
count
>
1
:
print
(
"|-
%
d
%
s"
%
(
corpus_id
,
corpus_name
))
print
(
" |-
%
s docs"
%
count
)
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