Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrations #124

Merged
merged 4 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions migrate.py
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()
13 changes: 13 additions & 0 deletions migrations/20200820_users_major_to_array.py
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)
10 changes: 10 additions & 0 deletions migrations/_20200806_example.py
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": ""}})
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jsonschema==2.6.0
lazy-object-proxy==1.3.1
mccabe==0.6.1
mock==4.0.2
mongodb-migrations==0.7.0
more-itertools==5.0.0
oauth2client==4.1.3
oauthlib==3.1.0
Expand All @@ -46,6 +47,7 @@ rsa==4.7
s3transfer==0.2.1
six==1.12.0
sparkpost==1.3.6
titlecase==1.1.1
typed-ast==1.4.3
uritemplate==3.0.0
urllib3==1.24.2
Expand Down