Eric Mc Sween d0a9f8c2cb Merge pull request #15748 from overleaf/em-drop-docops-collection %!s(int64=2) %!d(string=hai) anos
..
lib d0a9f8c2cb Merge pull request #15748 from overleaf/em-drop-docops-collection %!s(int64=2) %!d(string=hai) anos
20190720165251_create_migrations.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190730093801_script_example.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145001_create_contacts_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145002_create_deletedProjects_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145003_create_deletedSubscriptions_indexes.js be72e6ab19 Merge pull request #4806 from overleaf/jk-un-tag-migration %!s(int64=5) %!d(string=hai) anos
20190912145004_create_docHistoryIndex_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145005_create_docHistory_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145006_create_docOps_indexes.js d0a9f8c2cb Merge pull request #15748 from overleaf/em-drop-docops-collection %!s(int64=2) %!d(string=hai) anos
20190912145007_create_docSnapshots_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145008_create_docs_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145009_create_githubSyncEntityVersions_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145010_create_githubSyncProjectStates_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145011_create_githubSyncUserCredentials_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145012_create_institutions_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145013_create_messages_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145014_create_notifications_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145015_create_oauthAccessTokens_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145016_create_oauthApplications_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145017_create_oauthAuthorizationCodes_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145018_create_projectHistoryFailures_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145019_create_projectHistoryLabels_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145020_create_projectHistoryMetaData_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145021_create_projectHistorySyncState_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145022_create_projectImportFailures_indexes.js eef5cd00e3 Merge pull request #6247 from overleaf/jpa-cleanup-mongo %!s(int64=4) %!d(string=hai) anos
20190912145023_create_projectInvites_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145024_create_projects_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145025_create_publishers_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145026_create_rooms_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145027_create_spellingPreferences_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145028_create_subscriptions_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145029_create_tags_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145030_create_templates_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145031_create_tokens_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20190912145032_create_users_indexes.js 50df230846 [web] Upgrade Prettier to match version in monorepo root (#6231) %!s(int64=4) %!d(string=hai) anos
20190912145033_create_userstubs_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20191106102104_saml-log-indexes.js eef5cd00e3 Merge pull request #6247 from overleaf/jpa-cleanup-mongo %!s(int64=4) %!d(string=hai) anos
20191107191318_saml-indentifiers-index.js eef5cd00e3 Merge pull request #6247 from overleaf/jpa-cleanup-mongo %!s(int64=4) %!d(string=hai) anos
20200110183327_brandVarationIdIndex.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20200120163346_atlas_recommended_indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20200210084301_remove-duplicate-deleted-things.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20200210121103_uniqueify-deletedthings-indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20200302143624_users_affiliationUnchecked_index.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20200522145727_dropProjectImportFailures.js eef5cd00e3 Merge pull request #6247 from overleaf/jpa-cleanup-mongo %!s(int64=4) %!d(string=hai) anos
20200522145741_dropProjectImportBatchRecords.js eef5cd00e3 Merge pull request #6247 from overleaf/jpa-cleanup-mongo %!s(int64=4) %!d(string=hai) anos
20200608213302_saml-cache-indexes.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20200729120824_update_subscriptions_manager_ids_index.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20201106094956_active-projects-index-with-id.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20210310111225_create_deletedFiles_projectId_index.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20210407085118_token-expiry-with-ttl-index.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20210408123210_create_docs_project_id_deleted_deletedAt_index.js 4b9aa97ea1 Merge pull request #4303 from overleaf/sk-tag-saas-migrations %!s(int64=5) %!d(string=hai) anos
20210721081758_create_history_display_index.js 35ee137067 Create migration to add history display state index (#4335) %!s(int64=5) %!d(string=hai) anos
20210726083523_convert_confirmedAt_strings_to_dates.js 33bd9b6d43 Merge pull request #4350 from overleaf/ns-migration-tags %!s(int64=5) %!d(string=hai) anos
20210726083523_convert_split_tests_assigned_at_strings_to_dates.js 735f79ab6a Merge pull request #5364 from overleaf/ta-split-test-assignment-date-backfill %!s(int64=4) %!d(string=hai) anos
20210727123346_ce_sp_backfill_deleted_files.js 99fe2eca51 Merge pull request #4352 from overleaf/sk-add-ce-sp-migration-deleted-files %!s(int64=5) %!d(string=hai) anos
20210727150530_ce_sp_backfill_deleted_docs.js 99fe2eca51 Merge pull request #4352 from overleaf/sk-add-ce-sp-migration-deleted-files %!s(int64=5) %!d(string=hai) anos
20210728115327_ce_sp_backfill_dummy_doc_meta.js 99fe2eca51 Merge pull request #4352 from overleaf/sk-add-ce-sp-migration-deleted-files %!s(int64=5) %!d(string=hai) anos
20210924140139_splittests-name-index.js eef5cd00e3 Merge pull request #6247 from overleaf/jpa-cleanup-mongo %!s(int64=4) %!d(string=hai) anos
20220105123000_cleanup_unused_collections.js eef5cd00e3 Merge pull request #6247 from overleaf/jpa-cleanup-mongo %!s(int64=4) %!d(string=hai) anos
20220105130000_fix_saml_indexes.js a6625e872f Merge pull request #6297 from overleaf/jpa-fix-index %!s(int64=4) %!d(string=hai) anos
20220222095146_split_tests_analytics_enabled.js 5ded04eaea Merge pull request #6785 from overleaf/em-split-tests-analytics-enabled %!s(int64=4) %!d(string=hai) anos
20220811111800_create_dropboxEntities_index.js e293c627a1 Merge pull request #9212 from overleaf/jpa-record-dropbox-file-id %!s(int64=4) %!d(string=hai) anos
20220815105500_create_dropboxProjects_index.js 7225f3ea75 Merge pull request #9291 from overleaf/jpa-dropbox-project-id %!s(int64=4) %!d(string=hai) anos
20220817120900_create_dropboxProjects_index.js 55c1f852d6 Merge pull request #9447 from overleaf/jpa-dropbox-refresh-project-folder-names %!s(int64=4) %!d(string=hai) anos
20220825160708_recreate_dropboxEntities.js 03d8ad5eea Merge pull request #9455 from overleaf/em-recreate-dropbox-entities %!s(int64=4) %!d(string=hai) anos
20220826104236_disable_alpha_beta_program.js 01a1546639 [migration] disable `betaProgram` in CE/SP (#9418) %!s(int64=4) %!d(string=hai) anos
20220830140459_create_index_user_labsProgram_labsProgramGalileo.js 73e8fd115b Merge pull request #9466 from overleaf/jk-add-labs-program-for-galileo %!s(int64=3) %!d(string=hai) anos
20220913105500_create_auditLog_indexes.js 74f44e655a Merge pull request #9617 from overleaf/msm-audit-log-collections %!s(int64=3) %!d(string=hai) anos
20220913125500_migrate_auditLog_to_collections.js f97e64ab52 Merge pull request #16433 from overleaf/jpa-migrate-audit-log-dev-env %!s(int64=2) %!d(string=hai) anos
20220929193200_add_auditLog_indexes.js 9a3b5f1c76 Merge pull request #9800 from overleaf/msm-audit-indices %!s(int64=3) %!d(string=hai) anos
20221111111111_ce_sp_convert_archived_state.js d4551dc7ce Merge pull request #10442 from overleaf/jpa-convert-archived-trashed %!s(int64=3) %!d(string=hai) anos
20221122191857_project_history_chunks_indexes.js 3efcd3e52b Merge pull request #10644 from overleaf/em-chunk-store-mongo %!s(int64=3) %!d(string=hai) anos
20230110140452_rename_recurly_cached_status.js aa9b07d323 Merge pull request #11445 from overleaf/revert-11432-revert-11154-tm-lg-subscription-recurly-cache-name %!s(int64=3) %!d(string=hai) anos
20230124092607_clear_old_2fa_setup.js dd906df7b7 Merge pull request #11360 from overleaf/jpa-encrypt-2fa-secret %!s(int64=3) %!d(string=hai) anos
20230207134844_group_invite_emails_to_lowercase.js 41b5bb5bae Merge pull request #11711 from overleaf/tm-invite-emails-lowercase-readd-migration %!s(int64=3) %!d(string=hai) anos
20230217205311_fix_deleted_history_chunks_index.js e41d3cf5db Merge pull request #11890 from overleaf/em-fix-deleted-chunks-indexes %!s(int64=3) %!d(string=hai) anos
20230315170739_back_fill_doc_rev.js fa5804a3cf Merge pull request #12254 from overleaf/jpa-back-fill-doc-rev %!s(int64=3) %!d(string=hai) anos
20230405190240_oauth_refresh_tokens_index.js 1f9cfd877a Merge pull request #12536 from overleaf/em-oauth-refresh-tokens-index %!s(int64=3) %!d(string=hai) anos
20230406125632_oauth_tokens_ttl.js fb1f61434a Merge pull request #12545 from overleaf/em-oauth-tokens-ttl %!s(int64=3) %!d(string=hai) anos
20230426095212_personal_oauth_tokens_user_index.js d2172e5179 [web] Issue Oauth2 access tokens (#12788) %!s(int64=3) %!d(string=hai) anos
20230428154643_history_chunks_garbage_collection_index.js 66d29940c3 Merge pull request #12861 from overleaf/em-ds-delete-chunk-migration %!s(int64=3) %!d(string=hai) anos
20230502180757_server_pro_oauth_indexes.js d5242379f2 Merge pull request #12912 from overleaf/em-server-pro-oauth-indexes %!s(int64=3) %!d(string=hai) anos
20230512100122_ensure_history_migration.js 234eb31ffb Merge pull request #13082 from overleaf/msm-migration-check-history %!s(int64=3) %!d(string=hai) anos
20230616153016_user_features_updated_at_index.js 6ee5f6a0a0 Merge pull request #13497 from overleaf/jdt-extract-user-feature-set %!s(int64=3) %!d(string=hai) anos
20230817081910_back_fill_gitBridge_feature_server_pro.js c5bb18045e Merge pull request #14383 from overleaf/jpa-server-pro-feature-refresh-migration %!s(int64=3) %!d(string=hai) anos
20230928092537_backfill_subscriptions_managed_users_feature_flag.js 7268e0f0aa Merge pull request #15084 from overleaf/ab-managers-users-ga %!s(int64=2) %!d(string=hai) anos
20231016101457_drop_history_display_index.js 781a827e05 Merge pull request #15270 from overleaf/em-drop-history-display-index %!s(int64=2) %!d(string=hai) anos
20231025094810_sso_config_certificates_array.js c71301ac9a Merge pull request #15223 from overleaf/ab-sso-multiple-certificates-ui %!s(int64=2) %!d(string=hai) anos
20231030160030_managed_users_enabled.js 451a6e958f adding DB migration for managedUserEnabled flag (#15516) %!s(int64=2) %!d(string=hai) anos
20231031164732_drop_redundant_indexes.js 960701d143 Merge pull request #15541 from overleaf/em-drop-redundant-indexes %!s(int64=2) %!d(string=hai) anos
20231101153447_partial_last_opened_index.js f09f72d2da Merge pull request #15555 from overleaf/em-partial-last-opened-index %!s(int64=2) %!d(string=hai) anos
20231101191643_drop_unused_indexes.js 348bdf7907 Merge pull request #15562 from overleaf/em-drop-unused-indexes %!s(int64=2) %!d(string=hai) anos
20231101204352_drop_unused_saas_indexes.js 348bdf7907 Merge pull request #15562 from overleaf/em-drop-unused-indexes %!s(int64=2) %!d(string=hai) anos
20231110192205_drop_docops_collection.js d0a9f8c2cb Merge pull request #15748 from overleaf/em-drop-docops-collection %!s(int64=2) %!d(string=hai) anos
20231113173237_tokens_user_id_index.js 2807a35e24 Merge pull request #15728 from overleaf/td-lg-expire-password-tokens %!s(int64=2) %!d(string=hai) anos
20231219081700_move_doc_versions_from_docops_to_docs.js d0a9f8c2cb Merge pull request #15748 from overleaf/em-drop-docops-collection %!s(int64=2) %!d(string=hai) anos
20240115172206_oauth_issuer_index.js a68b0b2793 Merge pull request #16527 from overleaf/jpa-wf-hint-oauth %!s(int64=2) %!d(string=hai) anos
README.md e120f61a9a Merge pull request #15921 from overleaf/jpa-migrations-via-rake %!s(int64=2) %!d(string=hai) anos

README.md

Migrations

Migrations for the app environment live in this folder, and use the East migration framework.

We have a npm script which wraps east: npm run migrations -- ...

For example:

npm run migrations -- list -t 'server-ce'

For SAAS, use the rake tasks for staging/production

rake deploy:migrations:list[staging]

Environments and Tags

Overleaf is deployed in three different environments:

  • server-ce: community edition installations (the base system)
  • server-pro: server pro installations
  • saas: the production overleaf site

All migrations are tagged with the environments they should run in. For example, a migration that should run in every environment would be tagged with ['server-ce', 'server-pro', 'saas'].

When invoking east, we specify the relevant tags with the -t or --tags flag. Our adapter will refuse to run if this flag is not set.

Creating new migrations

To create a new migration, run:

npm run migrations -- create <migration name>

This command will create a new migration file in the migrations folder, based on a template. The template provides migrate and rollback methods, which are run by the east binary when running the migrations. rollback should undo the changes made in migrate.

Running scripts as a migration

To run a script in a migration file, look at migrations/20190730093801_script_example.js, which runs the script scripts/example/script_for_migration.js. This uses a method where the script can be run standalone via node, or through the migrations' mechanism.

Running migrations

To run all migrations in a server-ce environment:

npm run migrations -- migrate -t 'server-ce'
# Note: They are run by default on container start.

To run all migrations in a SAAS environment use the rake task:

# list first and check that only your newly added migration is shown. If not, ask in the dev channel for help.
rake deploy:migrations:list[staging]
# After confirming the listing, run the migrations
rake deploy:migrations[staging]

To run all migrations in the dev-env:

make services/web/migrate
# Note: "make install" will pick them up as well

The -t flag also works with other east commands like rollback, and list.

For other options, or for information on how to roll migrations back, take a look at the East documentation.

Tips

Try to use Mongo directly via the db object instead of using Mongoose models. Migrations will need to run in the future, and model files can change. It's unwise to make the migrations depend on code which might change.

Note: Running east rollback without any arguments rolls back all migrations, which you may well not want.