Skip to content

Instantly share code, notes, and snippets.

@delba
Last active December 17, 2015 15:09
Show Gist options
  • Select an option

  • Save delba/5629289 to your computer and use it in GitHub Desktop.

Select an option

Save delba/5629289 to your computer and use it in GitHub Desktop.
ActiveRecord::Migration outside of Rails
DB_FILE = 'tmp/test_db'
FileUtils.mkdir_p File.dirname(DB_FILE)
FileUtils.rm_f DB_FILE
ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: DB_FILE
ActiveRecord::Migration.class_exec do
self.verbose = false
create_table :users do |t|
t.string :username
t.index :username, unique: true
t.string :email
t.index :email, unique: true
end
create_table :articles do |t|
t.string :title
t.text :content
t.references :user
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment