Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Metagenomics
metagenedb
Commits
e2ada726
Commit
e2ada726
authored
Apr 13, 2021
by
Kenzo-Hugo Hillion
♻
Browse files
update migration to create virgo and IGC and link them to genes
parent
220b2f71
Changes
2
Hide whitespace changes
Inline
Side-by-side
backend/metagenedb/apps/catalog/migrations/0029_source.py
View file @
e2ada726
# Generated by Django 3.1.7 on 2021-04-12 10:07
from
django.db
import
migrations
,
models
import
django.db.models.deletion
def
create_sources
(
apps
,
schema_editor
):
Source
=
apps
.
get_model
(
'catalog'
,
'Source'
)
items_to_create
=
[
{
'name'
:
'Virgo'
,
'url'
:
'https://virgo.igs.umaryland.edu/'
,
'doi'
:
'10.1038/s41467-020-14677-3'
},
{
'name'
:
'IGC-9.9M'
,
'url'
:
'https://db.cngb.org/microbiome/genecatalog/genecatalog_human/'
,
'doi'
:
'10.1038/s41467-020-14677-3'
},
]
for
item
in
items_to_create
:
new_entry
=
Source
(
**
item
)
new_entry
.
save
()
def
link_to_source
(
apps
,
schema_editor
):
Gene
=
apps
.
get_model
(
'catalog'
,
'Gene'
)
Source
=
apps
.
get_model
(
'catalog'
,
'Source'
)
mapping_source
=
{
'igc'
:
Source
.
objects
.
get
(
name
=
'IGC-9.9M'
),
'virgo'
:
Source
.
objects
.
get
(
name
=
'Virgo'
)
}
for
row
in
Gene
.
objects
.
all
():
if
row
.
source
!=
'undef'
:
row
.
new_source
=
mapping_source
.
get
(
row
.
source
)
row
.
save
()
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
...
...
@@ -20,4 +52,20 @@ class Migration(migrations.Migration):
(
'tools'
,
models
.
JSONField
(
blank
=
True
,
null
=
True
)),
],
),
migrations
.
RunPython
(
create_sources
),
migrations
.
AddField
(
model_name
=
'gene'
,
name
=
'new_source'
,
field
=
models
.
ForeignKey
(
blank
=
True
,
null
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
SET_NULL
,
related_name
=
'genes'
,
to
=
'catalog.source'
),
),
migrations
.
RunPython
(
link_to_source
),
migrations
.
RemoveField
(
model_name
=
'gene'
,
name
=
'source'
,
),
migrations
.
RenameField
(
model_name
=
'gene'
,
old_name
=
'new_source'
,
new_name
=
'source'
,
),
]
backend/metagenedb/apps/catalog/migrations/0030_gene_new_source.py
deleted
100644 → 0
View file @
220b2f71
# Generated by Django 3.1.7 on 2021-04-12 10:26
from
django.db
import
migrations
,
models
import
django.db.models.deletion
def
link_to_source
(
apps
,
schema_editor
):
Gene
=
apps
.
get_model
(
'catalog'
,
'Gene'
)
Source
=
apps
.
get_models
(
'catalog'
,
'Source'
)
mapping_source
=
{
'igc'
:
Source
.
objects
.
get
(
name
=
'IGC-9.9M'
),
'virgo'
:
Source
.
objects
.
get
(
name
=
'Virgo'
)
}
for
row
in
Gene
.
objects
.
all
():
print
(
row
.
source
)
if
row
.
source
!=
'undef'
:
row
.
new_source
=
mapping_source
.
get
(
row
.
source
)
row
.
save
()
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'catalog'
,
'0029_source'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'gene'
,
name
=
'new_source'
,
field
=
models
.
ForeignKey
(
blank
=
True
,
null
=
True
,
on_delete
=
django
.
db
.
models
.
deletion
.
SET_NULL
,
related_name
=
'genes'
,
to
=
'catalog.source'
),
),
migrations
.
RemoveField
(
model_name
=
'gene'
,
name
=
'source'
,
),
migrations
.
RenameField
(
model_name
=
'gene'
,
old_name
=
'new_source'
,
new_name
=
'source'
,
),
]
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