aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/migration.rb
Commit message (Collapse)AuthorAgeFilesLines
* Prevent destructive action on production databaseschneems2016-01-071-1/+36
| | | | | | | This PR introduces a key/value type store to Active Record that can be used for storing internal values. It is an alternative implementation to #21237 cc @sgrif @matthewd. It is possible to run your tests against your production database by accident right now. While infrequently, but as an anecdotal data point, Heroku receives a non-trivial number of requests for a database restore due to this happening. In these cases the loss can be large. To prevent against running tests against production we can store the "environment" version that was used when migrating the database in a new internal table. Before executing tests we can see if the database is a listed in `protected_environments` and abort. There is a manual escape valve to force this check from happening with environment variable `DISABLE_DATABASE_ENVIRONMENT_CHECK=1`.
* Use a real migration version number in docsMatthew Draper2015-12-151-15/+15
| | | | | Even though this means more things to change when we bump after a release, it's more important that our examples are directly copyable.
* Find the delegate, even in a deeper inheritance treeMatthew Draper2015-12-151-1/+5
|
* Use a deliberately-invalid migration version in all doc examplesMatthew Draper2015-12-151-15/+15
| | | | | | | | | | If we use a real version, at best that'll be an onerous update required for each release; at worst, it will encourage users to write new migrations against an older version than they're using. The other option would be to leave these bare, without any version specifier. But as that's just a variant spelling of "4.2", it would seem to raise the same concerns as above.
* Add migration versioning via Migration subclassesMatthew Draper2015-12-151-0/+26
|
* Rename 'key' to 'lock_id' or 'lock_name' for advisory lockingSam Davies2015-11-181-4/+4
| | | | | | | | | - key was a poor choice of name. A key implies something that will unlock a lock. The concept is actually more like a 'lock identifier' - mysql documentation calls this a 'lock name' - postgres documentation calls it a 'lock_id' - Updated variable names to reflect the preferred terminology for the database in question
* Deprecate `#table_exists?`, `#tables` and passing arguments to `#talbes`yui-knk2015-11-091-4/+6
| | | | | | | | | | Reported on #21509, how views is treated by `#tables` are differ by each adapters. To fix this different behavior, after Rails 5.0 is released, deprecate `#tables`. And `#table_exists?` would check both tables and views. To make their behavior consistent with `#tables`, after Rails 5.0 is released, deprecate `#table_exists?`.
* Make `db:migrate:status` to render `1_some.rb` format migrate files.yui-knk2015-11-021-2/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `1_valid_people_have_last_names.rb` and `20150823202140_create_users.rb` are valid migration file name. But `1_valid_people_have_last_names.rb` is rendered as `********** NO FILE **********` when `rake db:migrate:status`. Fix to this bug, this commit includes * define some API private methdos and a Constant `match_to_migration_filename?`, `parse_migration_filename`, and `MigrationFilenameRegexp` * use these methods in `db:migrate:status` task Example: These files are in `db/migrate` * 1_valid_people_have_last_names.rb * 20150819202140_irreversible_migration.rb * 20150823202140_add_admin_flag_to_users.rb * 20150823202141_migration_tests.rb * 2_we_need_reminders.rb * 3_innocent_jointable.rb we can migrate all of them. Before ```shell $ bundle exec rake db:migrate:status ... Status Migration ID Migration Name -------------------------------------------------- up 001 ********** NO FILE ********** up 002 ********** NO FILE ********** up 003 ********** NO FILE ********** up 20150819202140 Irreversible migration up 20150823202140 Add admin flag to users up 20150823202141 Migration tests ``` After ```shell $ bundle exec rake db:migrate:status ... Status Migration ID Migration Name -------------------------------------------------- up 001 Valid people have last names up 002 We need reminders up 003 Innocent jointable up 20150819202140 Irreversible migration up 20150823202140 Add admin flag to users up 20150823202141 Migration tests ```
* Use advisory locks to prevent concurrent migrationsSam Davies2015-10-301-23/+72
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Addresses issue #22092 - Works on Postgres and MySQL - Uses advisory locks because of two important properties: 1. The can be obtained outside of the context of a transaction 2. They are automatically released when the session ends, so if a migration process crashed for whatever reason the lock is not left open perpetually - Adds get_advisory_lock and release_advisory_lock methods to database adapters - Attempting to run a migration while another one is in process will raise a ConcurrentMigrationError instead of attempting to run in parallel with undefined behavior. This could be rescued and the migration could exit cleanly instead. Perhaps as a configuration option? Technical Notes ============== The Migrator uses generate_migrator_advisory_lock_key to build the key for the lock. In order to be compatible across multiple adapters there are some constraints on this key. - Postgres limits us to 64 bit signed integers - MySQL advisory locks are server-wide so we have to scope to the database - To fulfil these requirements we use a Migrator salt (a randomly chosen signed integer with max length of 31 bits) that identifies the Rails migration process as the owner of the lock. We multiply this salt with a CRC32 unsigned integer hash of the database name to get a signed 64 bit integer that can also be converted to a string to act as a lock key in MySQL databases. - It is important for subsequent versions of the Migrator to use the same salt, otherwise different versions of the Migrator will not see each other's locks.
* Merge pull request #20934 from maurogeorge/migration-transformations-docSean Griffin2015-10-201-15/+51
|\ | | | | | | Add missed available transformations to Migration Doc [ci skip]
| * Add missed Available transformations to migration DocMauro George2015-07-221-15/+50
| | | | | | | | [ci skip]
* | Merge branch 'master' of github.com:rails/docrailsVijay Dev2015-10-041-1/+1
|\ \
| * | [ci skip] Fix commentyui-knk2015-10-021-1/+1
| | | | | | | | | | | | | | | `alias :migrations_path= :migrations_paths=`, so `migrations_path = some_string` is correct.
* | | Fix minor docs [ci skip] amitkumarsuroliya2015-09-281-1/+1
|/ /
* | remove dead code.Yves Senn2015-09-091-4/+0
| | | | | | | | | | | | The last call site of `last_version` was removed with: 838e18321118ee3ec6669217e5ea0216f79c969a
* | remove dead code.Yves Senn2015-09-091-4/+0
| | | | | | | | This method is private API and never used. Let's remove it.
* | Make ActiveRecordException descendants args optionalPavel Pravosud2015-09-071-12/+30
| | | | | | | | | | | | This change allows to instantiate all ActiveRecordError descendant execption classes without arguments, which might be useful in testing and is far less surprising than mandatory arguments.
* | Merge pull request #21412 from yui-knk/feature/irreversible_migration_error_msgYves Senn2015-09-041-1/+71
|\ \ | | | | | | | | | Add detailed error message to `IrreversibleMigration`
| * | [ci skip] Add comments for `IrreversibleMigration`yui-knk2015-08-291-0/+70
| | |
* | | Merge branch 'master' of github.com:rails/docrailsVijay Dev2015-08-301-1/+1
|\ \ \ | |/ / |/| |
| * | [ci skip] Fix file name generated by `rails generate`yui-knk2015-08-241-1/+1
| | |
* | | Merge pull request #21336 from yui-knk/refactor/to_use_getterRafael Mendonça França2015-08-261-7/+7
|\ \ \ | | | | | | | | Use `ActiveRecord::Migration#connection` instead of `@connection`
| * | | Use `ActiveRecord::Migration#connection` instead of `@connection`yui-knk2015-08-231-7/+7
| | | | | | | | | | | | | | | | | | | | `ActiveRecord::Migration` has `connetion` method so replace to use `connection` method to get `@connection` as much as possible
* | | | [ci skip] Fix migration file's timestampyui-knk2015-08-241-1/+1
| |/ / |/| | | | | | | | In rails generally migration file's timestamp is "YYYYMMDDHHMMSS".
* | | Remove not used a block argument (`&block`)yui-knk2015-08-231-1/+1
|/ /
* | better docs for `disable_ddl_transaction!`. Closes #21044.Yves Senn2015-08-211-1/+4
| |
* | Merge pull request #21283 from ravindrakumawat/add_docs_for_pending_migrationYves Senn2015-08-181-0/+1
|\ \ | | | | | | Add Docs for ActiveRecord #check_pending [ci skip]
| * | Add Docs for ActiveRecord #check_pending [ci skip]ravindra kumar kumawat2015-08-181-0/+1
| | |
* | | better docs for ActiveRecord::Migration#table_name_optionsBrendan Buckingham2015-08-061-1/+3
| |/ |/|
* | Add table name prefix and suffix support to add_foreign_key and ↵Mehmet Emin İNAÇ2015-06-251-1/+2
| | | | | | | | | | | | remove_foreign_key methods fix tests
* | Merge pull request #20259 from rastasheep/rastasheep-patch-1Yves Senn2015-06-191-2/+2
|\ \ | | | | | | | | | Update documentation for ActiveRecord::Migration#remove_index
| * | Fix typo [ci skip]Aleksandar Diklic2015-05-221-2/+2
| |/ | | | | | | `remove_index` works with multiple column names as `add_index`
* | Merge pull request #20550 from maurogeorge/add_reference-rdocYves Senn2015-06-151-0/+3
|\ \ | |/ |/| | | | | | | Add RDoc about add_reference to ActiveRecord::Migration [ci skip]
| * Add RDoc about add_reference to ActiveRecord::MigrationMauro George2015-06-131-0/+6
|/ | | | [ci skip]
* [ci skip] Remove comments about Rails 3.1claudiob2015-05-111-15/+0
| | | | | | | | | Stems from https://github.com/rails/rails/pull/20105#issuecomment-100900939 where @senny said: > From my point of view, all the docs (guides, API) are version bound. > They should describe that version and continue to be available when newer versions are released. > The cross referencing can be done by the interested user.
* [ci skip] Fix comment, since Rails 3.1 is outclaudiob2015-05-111-2/+1
|
* Fix typo [ci skip]Luke Hutscal2015-02-231-1/+1
| | | | I think this was supposed to be "roundTrip".
* fix column name in migration example [ci skip]Daniël de Vries2015-02-191-1/+1
|
* Do not check only for the Rails constantRafael Mendonça França2015-01-021-1/+1
| | | | | This constant may be define for auxiliar gems like rails-html-sanitizer and these methods call will fail.
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-291-1/+1
|
* bring back `db:test:prepare`.Yves Senn2014-11-251-1/+8
| | | | | | | | | | | | | | | This reverts deprecations added in #13528. The task is brought back for two reasons: 1. Give plugins a way to hook into the test database initialization process 2. Give the user a way to force a test database synchronization While `test:prepare` is still a dependency of every test task, `db:test:prepare` no longer hooks into it. This means that `test:prepare` runs before the schema is synchronized. Plugins, which insert data can now hook into `db:test:prepare`. The automatic schema maintenance can't detect when a migration is rolled-back, modified and reapplied. In this case the user has to fall back to `db:test:prepare` to force the synchronization to happen.
* cleanup, remove trailing whitespace [ci skip]Yves Senn2014-11-241-2/+2
|
* Don't attempt to load the schema file in tests if none existsSean Griffin2014-10-311-1/+1
|
* Load test schema even if there are no migrationsSean Griffin2014-10-311-1/+5
| | | | Fixes #17170
* [ci skip] add doc for STEP in migrationAditya Kapoor2014-08-211-3/+6
|
* [ci skip] correct docs about the migration generationAditya Kapoor2014-08-211-9/+2
|
* Correctly determine if migration is needed.Jeremy McNevin2014-08-131-9/+8
| | | | | | | This method would assume that if last migration in the migrations directory matched the current schema version, that the database was up to date, but this does not account for new migrations with older timestamps that may be pending.
* schema rake tasks are specific about the configuration to act on.Yves Senn2014-08-061-1/+1
| | | | | | | | | | The rake tasks and the `DatabaseTakss` adapter classes used to assume a configuration at some places. This forced the rake tasks to establish a specific connection before calling into `load_schema`. After #15394 this started to cause issues because it could `purge` the wrong database before loading the schema.
* Remove redundant `self.` in class method callsJack Danger Canty2014-07-301-5/+5
| | | | These are the only instances of this in the whole code base.
* do not hold on to a stale connection object. fixes #15998Aaron Patterson2014-07-011-4/+9
|