Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 202 lines (150 sloc) 6.149 kb
beed672 @febuiles Fixing filename translation for new migrations. Fixes #31.
febuiles authored
1 Rails migrations in non-Rails (and non Ruby) projects.
dec36de @grosser fill readme with what is coming...
grosser authored
2
113b60e @thuss Updated README
thuss authored
3 WHAT'S NEW
4 ==========
27bde08 @thuss Added support for db:seed
thuss authored
5 In the 1.0.x release we have moved to using Rails 3 migrations instead of maintaining our own migration related code. Just about anything you can do with Rails 3 migrations you can now do with [Standalone Migrations](https://github.com/thuss/standalone-migrations) too! This removed 95% of the code we have to maintain. Big thanks to [Michael Grosser](http://pragmatig.wordpress.com) for undertaking this major rewrite!
113b60e @thuss Updated README
thuss authored
6
7 CONTRIBUTE
8 ==========
9 [Standalone Migrations](https://github.com/thuss/standalone-migrations) relies on the contributions of the open-source community! To submit a fix or an enhancement fork the repository, checkout the *develop* branch, make your changes, add your name to the *Contributors* section in README.markdown, and send us a pull request! If you're active and do good work we'll add you as a collaborator!
10
dec36de @grosser fill readme with what is coming...
grosser authored
11 USAGE
12 =====
7fb692b @grosser make readme pretty
grosser authored
13 Install Ruby, RubyGems and a ruby-database driver (e.g. `gem install mysql`) then:
7499e14 @richmeyers Added empty lines to readme to have code blocks correctly rendered on gi...
richmeyers authored
14
a7ecb6d @thuss Switched the gem name back to standalone_migrations
thuss authored
15 sudo gem install standalone_migrations
dec36de @grosser fill readme with what is coming...
grosser authored
16
17 Add to `Rakefile` in your projects base directory:
7499e14 @richmeyers Added empty lines to readme to have code blocks correctly rendered on gi...
richmeyers authored
18
97f389d @ricardovaleriano omg! a colored readme (syntax highlight)
ricardovaleriano authored
19 ```ruby
20 begin
21 require 'tasks/standalone_migrations'
22 rescue LoadError => e
23 puts "gem install standalone_migrations to get db:migrate:* tasks! (Error: #{e})"
24 end
25 ```
dec36de @grosser fill readme with what is coming...
grosser authored
26
b7b92a0 @grosser move tasks into lib/tasks, as rails plugins now do it
grosser authored
27 Add database configuration to `db/config.yml` in your projects base directory e.g.:
7e9ee9c @ricardovaleriano Not so well =/
ricardovaleriano authored
28
dec36de @grosser fill readme with what is coming...
grosser authored
29 development:
6bb0c55 @stevehodgkiss Update readme
stevehodgkiss authored
30 adapter: sqlite3
31 database: db/development.sqlite3
32 pool: 5
33 timeout: 5000
34
35 production:
dec36de @grosser fill readme with what is coming...
grosser authored
36 adapter: mysql
37 encoding: utf8
38 reconnect: false
39 database: somedatabase_dev
40 pool: 5
41 username: root
42 password:
43 socket: /var/run/mysqld/mysqld.sock
44
6bb0c55 @stevehodgkiss Update readme
stevehodgkiss authored
45 test: &test
46 adapter: sqlite3
47 database: db/test.sqlite3
48 pool: 5
49 timeout: 5000
dec36de @grosser fill readme with what is coming...
grosser authored
50
7fb692b @grosser make readme pretty
grosser authored
51 ### To create a new database migration:
dec36de @grosser fill readme with what is coming...
grosser authored
52
ab30e3d @pyrat Update README.markdown
pyrat authored
53 rake db:new_migration name=foo_bar_migration
b50c831 @grosser adjust readme to changed interface
grosser authored
54 edit db/migrate/20081220234130_foo_bar_migration.rb
dec36de @grosser fill readme with what is coming...
grosser authored
55
b7ff503 @rberger Updated README and corrected some description lines that said DATABASE_E...
rberger authored
56 #### If you really want to, you can just execute raw SQL:
7fb692b @grosser make readme pretty
grosser authored
57
97f389d @ricardovaleriano omg! a colored readme (syntax highlight)
ricardovaleriano authored
58 ```ruby
59 def self.up
60 execute "insert into foo values (123,'something');"
61 end
7fb692b @grosser make readme pretty
grosser authored
62
97f389d @ricardovaleriano omg! a colored readme (syntax highlight)
ricardovaleriano authored
63 def self.down
64 execute "delete from foo where field='something';"
65 end
66 ```
7fb692b @grosser make readme pretty
grosser authored
67
68 ### To apply your newest migration:
dec36de @grosser fill readme with what is coming...
grosser authored
69
70 rake db:migrate
71
7fb692b @grosser make readme pretty
grosser authored
72 ### To migrate to a specific version (for example to rollback)
dec36de @grosser fill readme with what is coming...
grosser authored
73
74 rake db:migrate VERSION=20081220234130
75
7fb692b @grosser make readme pretty
grosser authored
76 ### To migrate a specific database (for example your "testing" database)
dec36de @grosser fill readme with what is coming...
grosser authored
77
113b60e @thuss Updated README
thuss authored
78 rake db:migrate DB=test ... or ...
79 rake db:migrate RAILS_ENV=test
dec36de @grosser fill readme with what is coming...
grosser authored
80
7cad214 @grosser add migrate-up and migrate-down tasks
grosser authored
81 ### To execute a specific up/down of one single migration
82
83 rake db:migrate:up VERSION=20081220234130
beed672 @febuiles Fixing filename translation for new migrations. Fixes #31.
febuiles authored
84
113b60e @thuss Updated README
thuss authored
85 ### To revert your last migration
7cad214 @grosser add migrate-up and migrate-down tasks
grosser authored
86
113b60e @thuss Updated README
thuss authored
87 rake db:rollback
88
89 ### To revert your last 3 migrations
a2753d1 @grosser gemfile-ify to pin down AR version
grosser authored
90
beed672 @febuiles Fixing filename translation for new migrations. Fixes #31.
febuiles authored
91 rake db:rollback STEP=3
a2753d1 @grosser gemfile-ify to pin down AR version
grosser authored
92
2ad2d12 @thuss Changing some language in the readme
thuss authored
93 ### Custom configuration
f137e44 @ricardovaleriano adding documentation (README) about the configuration file
ricardovaleriano authored
94
2ad2d12 @thuss Changing some language in the readme
thuss authored
95 By default, Standalone Migrations will assume there exists a "db/"
96 directory in your project. But if for some reason you need a specific
97 directory structure to work with, you can use a configuration file
98 named .standalone_migrations in the root of your project containing
99 the following:
f137e44 @ricardovaleriano adding documentation (README) about the configuration file
ricardovaleriano authored
100
1fc7302 @ricardovaleriano some love to ::environments_config example
ricardovaleriano authored
101 ```yaml
3bd1540 @ricardovaleriano Yaml examples with github flavored markdown.
ricardovaleriano authored
102 db:
103 seeds: db/seeds.rb
104 migrate: db/migrate
105 schema: db/schema.rb
106 config:
107 database: db/config.yml
1fc7302 @ricardovaleriano some love to ::environments_config example
ricardovaleriano authored
108 ```
f137e44 @ricardovaleriano adding documentation (README) about the configuration file
ricardovaleriano authored
109
2ad2d12 @thuss Changing some language in the readme
thuss authored
110 These are the configurable options available. You can omit any of
111 the keys and Standalone Migrations will assume the default values.
f137e44 @ricardovaleriano adding documentation (README) about the configuration file
ricardovaleriano authored
112
5cc87fc @ricardovaleriano documenting the ::environments_config method
ricardovaleriano authored
113 #### Changing environment config in runtime
4da7ec2 @ricardovaleriano updating README with runtime configuration feature
ricardovaleriano authored
114
54fca60 @ricardovaleriano some love to README
ricardovaleriano authored
115 If you are using Heroku or have to create or change your connection
116 configuration based on runtime aspects (maybe environment variables),
b40c59b @ricardovaleriano some love to README
ricardovaleriano authored
117 you can use the `StandaloneMigrations::Configurator.environments_config`
4da7ec2 @ricardovaleriano updating README with runtime configuration feature
ricardovaleriano authored
118 method. Check the usage example:
119
120 ```ruby
121 require 'tasks/standalone_migrations'
122
123 StandaloneMigrations::Configurator.environments_config do |env|
1fc7302 @ricardovaleriano some love to ::environments_config example
ricardovaleriano authored
124
125 env.on "production" do
126
127 if (ENV['DATABASE_URL'])
128 db = URI.parse(ENV['DATABASE_URL'])
129 return {
130 :adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
131 :host => db.host,
132 :username => db.user,
133 :password => db.password,
134 :database => db.path[1..-1],
135 :encoding => 'utf8'
136 }
137 end
138
5cc87fc @ricardovaleriano documenting the ::environments_config method
ricardovaleriano authored
139 nil
4da7ec2 @ricardovaleriano updating README with runtime configuration feature
ricardovaleriano authored
140 end
5cc87fc @ricardovaleriano documenting the ::environments_config method
ricardovaleriano authored
141
142 end
143 ```
144
145 You have to put this anywhere on your `Rakefile`. If you want to
146 change some configuration, call the #on method on the object
147 received as argument in your block passed to ::environments_config
148 method call. The #on method receives the key to the configuration
149 that you want to change within the block. The block should return
150 your new configuration hash or nil if you want the configuration
151 to stay the same.
152
153 Your logic to decide the new configuration need to access some data
154 in your current configuration? Then you should receive the configuration
155 in your block, like this:
156
157 ```ruby
158 require 'tasks/standalone_migrations'
159
160 StandaloneMigrations::Configurator.environments_config do |env|
161
162 env.on "my_custom_config" do |current_custom_config|
163 p current_custom_config
164 # => the values on your current "my_custom_config" environment
165 nil
166 end
167
4da7ec2 @ricardovaleriano updating README with runtime configuration feature
ricardovaleriano authored
168 end
169 ```
170
2364280 @caseywebdev Added note about generating SQL instead of migration syntax, addresses #...
caseywebdev authored
171 #### Exporting Generated SQL
172
173 If instead of the database-agnostic `schema.rb` file you'd like to
174 save the database-specific SQL generated by the migrations, simply
175 add this to your `Rakefile`.
176
177 ```ruby
178 require 'tasks/standalone_migrations'
179 ActiveRecord::Base.schema_format = :sql
180 ```
181
182 You should see a `db/structure.sql` file the next time you run a
183 migration.
184
7fb692b @grosser make readme pretty
grosser authored
185 Contributors
dec36de @grosser fill readme with what is coming...
grosser authored
186 ============
7fb692b @grosser make readme pretty
grosser authored
187 - [Todd Huss](http://gabrito.com/)
7a1be53 @thuss Updated contributors
thuss authored
188 - [Two Bit Labs](http://twobitlabs.com/)
2194a96 @thuss Bumped version number
thuss authored
189 - [Class Monkeys](http://www.classmonkeys.com/)
16c2780 @thuss Renamed the gem so I could publish it to rubygems.org based on Michael
thuss authored
190 - [Michael Grosser](http://pragmatig.wordpress.com)
1145a43 @grosser add eric to contributors
grosser authored
191 - [Eric Lindvall](http://bitmonkey.net)
1f326e7 Added credit to Rich and Wes for their submissions
Todd Huss authored
192 - [Steve Hodgkiss](http://stevehodgkiss.com/)
193 - [Rich Meyers](https://github.com/richmeyers)
b00561d @richmeyers Documentation for sub-namespaced tasks
richmeyers authored
194 - [Wes Bailey](http://exposinggotchas.blogspot.com/)
7a1be53 @thuss Updated contributors
thuss authored
195 - [Robert J. Berger](http://blog.ibd.com/)
beed672 @febuiles Fixing filename translation for new migrations. Fixes #31.
febuiles authored
196 - [Federico Builes](http://mheroin.com/)
f137e44 @ricardovaleriano adding documentation (README) about the configuration file
ricardovaleriano authored
197 - [Ricardo Valeriano](http://ricardovaleriano.com/)
27bde08 @thuss Added support for db:seed
thuss authored
198 - [Gazler](http://blog.gazler.com/)
2194a96 @thuss Bumped version number
thuss authored
199 - [Yuu Yamashita](https://github.com/yyuu)
7a1be53 @thuss Updated contributors
thuss authored
200
201 This work is originally based on [Lincoln Stoll's blog post](http://lstoll.net/2008/04/stand-alone-activerecord-migrations/) and [David Welton's post](http://journal.dedasys.com/2007/01/28/using-migrations-outside-of-rails).
Something went wrong with that request. Please try again.