Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
86ea11f4
Commit
86ea11f4
authored
5 years ago
by
Manon Blanco
Browse files
Options
Downloads
Patches
Plain Diff
add a reverse migration
parent
e040b89e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
arkindex/documents/migrations/0030_remove_entity_metatype.py
+20
-12
20 additions, 12 deletions
arkindex/documents/migrations/0030_remove_entity_metatype.py
with
20 additions
and
12 deletions
arkindex/documents/migrations/0030_remove_entity_metatype.py
+
20
−
12
View file @
86ea11f4
# Generated by Django 2.2 on 2019-12-13 10:28
from
django.db
import
migrations
from
arkindex_common.enums
import
EntityType
from
enum
import
Enum
def
remove_entity_metatype
(
apps
,
schema_editor
):
MetaData
=
apps
.
get_model
(
'
documents
'
,
'
MetaData
'
)
if
not
MetaData
.
objects
.
exists
():
return
class
OldMetaType
(
Enum
):
Text
=
'
text
'
...
...
@@ -15,17 +18,25 @@ def remove_entity_metatype(apps, schema_editor):
Reference
=
'
reference
'
Entity
=
'
entity
'
values
=
set
(
item
.
value
for
item
in
OldMetaType
)
# Don't try this at home
MetaData
.
_meta
.
fields
[
2
].
enum
=
OldMetaType
for
metadata
in
MetaData
.
objects
.
filter
(
type
=
OldMetaType
.
Entity
).
prefetch_related
(
'
entity
'
):
metadata_type
=
OldMetaType
.
Text
if
metadata
.
entity
and
metadata
.
entity
.
type
.
value
in
values
:
metadata_type
=
OldMetaType
(
metadata
.
entity
.
type
.
value
)
metadata
.
type
=
metadata_type
metadata
.
save
()
MetaData
.
objects
.
filter
(
type
=
OldMetaType
.
Entity
,
entity__type
=
EntityType
.
Location
).
update
(
type
=
OldMetaType
.
Location
)
MetaData
.
objects
.
filter
(
type
=
OldMetaType
.
Entity
,
entity__type
=
EntityType
.
Date
).
update
(
type
=
OldMetaType
.
Date
)
MetaData
.
objects
.
filter
(
type
=
OldMetaType
.
Entity
).
update
(
type
=
OldMetaType
.
Text
)
def
add_entity_metatype
(
apps
,
schema_editor
):
MetaData
=
apps
.
get_model
(
'
documents
'
,
'
MetaData
'
)
if
not
MetaData
.
objects
.
exists
():
return
class
OldMetaType
(
Enum
):
Entity
=
'
entity
'
# Don't try this at home
MetaData
.
_meta
.
fields
[
2
].
enum
=
OldMetaType
MetaData
.
objects
.
exclude
(
entity__isnull
=
True
).
update
(
type
=
OldMetaType
.
Entity
)
class
Migration
(
migrations
.
Migration
):
...
...
@@ -35,8 +46,5 @@ class Migration(migrations.Migration):
]
operations
=
[
migrations
.
RunPython
(
remove_entity_metatype
,
reverse_code
=
migrations
.
RunPython
.
noop
),
migrations
.
RunPython
(
remove_entity_metatype
,
add_entity_metatype
),
]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment