
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
After working with Mongo for long time now I can tell you working with a schemaless database does not mean you will never need any migrations. Within the same collection Mongo allows to have documents with a complete different structure, however in some case is you might want to keep data consistency; Especially when your code is live in production and used by millions of users.
There is a plenty of way to modify documents data structure and after a deep reflexion I realized it makes more sens to use migration framework. A migration framework provides a lot of advantages, such as:
Exodus has been used in production since March 2013.
Add this line to your application's Gemfile:
gem 'exodus'
And then execute bundle install:
$ bundle
Or install it yourself as:
$ gem install exodus
You need to configure 4 things before using Exodus: the database name, the mongodb connection, the config file location and the path to the directory that will include your migrations:
require 'exodus'
Exodus.configure do |config|
config.db = 'migration_db'
config.connection = Mongo::MongoClient.new("127.0.0.1", 27017, :pool_size => 5, :pool_timeout => 5)
config.config_file = File.dirname(__FILE__) + '/config/migrations.yml'
config.migrations_directory = File.dirname(__FILE__) + '/models/migrations'
end
Then you just need to loads the migrations tasks by adding the following line to your rakefile:
load Exodus.tasks
... And you're all set!
class RenameNameToFirstName < Exodus::Migration
self.migration_number = 1
def initialize(args = {})
super(args)
self.status_complete = 3
self.description = 'Change name to first_name'
end
def up
step("Creating first_name index", 1) do
puts Account.collection.ensure_index({:first_name => 1}, {:unique => true, :sparse => true})
end
step("Renaming", 2) do
puts Account.collection.update({'name' => {'$exists' => true}}, {'$rename' => {'name' => 'first_name'}},{:multi => true})
end
step("Dropping name index", 3) do
puts Account.collection.drop_index([[:name,1]])
end
self.status.message = "Migration Executed!"
end
def down
step("Creating name index", 2) do
puts Account.collection.ensure_index({:name => 1}, {:unique => true, :sparse => true})
end
step("Renaming", 1) do
puts Account.collection.update({'first_name' => {'$exists' => true}}, {'$rename' => {'first_name' => 'name'}},{:multi => true})
end
step("Dropping first_name index", 0) do
puts Account.collection.drop_index([[:first_name,1]])
end
self.status.message = "Rollback Executed!"
end
end
Executes all migrations that haven't run yet. You can the STEP enviroment to run only the first x ones.
rake db:migrate
rake db:migrate STEP=2
Rolls back all migrations that have already run. You can set the STEP enviroment variable to rollback only the last x ones.
rake db:rollback
rake db:rollback STEP=2
Rolls back all migrations that have already run and then run all migrations.
rake db:reset
Print in the console all migrations that rake db:migrate will run. Does NOT run any migration. You can the STEP enviroment to run only the first x ones.
rake db:migrate:show
rake db:migrate:show STEP=2
Print in the console all migrations that rake db:rollback will run. Does NOT run any migration. You can set the STEP enviroment variable to rollback only the last x ones.
rake db:rollback:show
rake db:rollback:show STEP=2
Executes all custom migrations that haven't run yet. Custom migrations will be loaded from your config file. Custom migrations will run in order of appearence. You can set the STEP enviroment variable to rollback only the last x ones.
rake db:migrate:custom
rake db:migrate:custom STEP=2
Executes all custom migrations that haven't run yet. Custom migrations will be loaded from your config file. Custom migrations will run in order of appearence. You can set the STEP enviroment variable to rollback only the last x ones.
rake db:rollback:custom
rake db:rollback:custom STEP=2
Lists all the migrations.
rake db:migrate:list
Gives a preview of what as been run on the current database.
rake db:migrate:status
Prints on the screen the content of the yml configuration file
rake db:migrate:yml_status
Prints on the screen information about the current mongo connection
rake db:mongo_info
You might be using other gems in your project that uses rake db:migrate
or rake db:rollback
. In order to avoid conflicts you can define rake_namespace, in the Ruby code:
Exodus.configure do |config|
config.rake_namespace = 'mongo'
end
Or in your Yaml file:
migration:
rake_namespace: 'mongo'
FAQs
Unknown package
We found that exodus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.