-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Migrations setup * Add major to array migration Co-authored-by: Lucent Fong <[email protected]> Co-authored-by: js324 <[email protected]>
- Loading branch information
1 parent
edb1115
commit 9ea25e3
Showing
4 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import config | ||
from mongodb_migrations.cli import MigrationManager | ||
|
||
mgr = MigrationManager() | ||
mgr.config.mongo_url = config.DB_URI | ||
mgr.config.metastore = 'migrations' | ||
mgr.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from mongodb_migrations.base import BaseMigration | ||
from titlecase import titlecase | ||
|
||
class Migration(BaseMigration): | ||
def upgrade(self): | ||
for u in self.db.users.find(): | ||
u['major'] = list(map(lambda s: titlecase(s.strip()), u['major'].split(';'))) | ||
self.db.users.save(u) | ||
|
||
def downgrade(self): | ||
for u in self.db.users.find(): | ||
u['major'] = u['major'].join(';') | ||
self.db.users.save(u) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from mongodb_migrations.base import BaseMigration | ||
|
||
class Migration(BaseMigration): | ||
def upgrade(self): | ||
for i in self.db.some_collection.find(): | ||
item['new_column'] = 'new_value' | ||
self.db.some_collection.save(item) | ||
|
||
def downgrade(self): | ||
self.db.some_collection.update_many({}, {"$unset": {"new_column": ""}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters