aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/migration_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* don't sleep in testsAaron Patterson2015-10-301-10/+6
| | | | | we should be using a countdown latch instead of rolling our own busy-loop.
* Use advisory locks to prevent concurrent migrationsSam Davies2015-10-301-0/+101
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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.
* remove dead code.Yves Senn2015-09-091-3/+1
| | | | | | The last call site of `last_version` was removed with: 838e18321118ee3ec6669217e5ea0216f79c969a
* Merge pull request #21342 from yui-knk/test/add_assert_methodRafael Mendonça França2015-08-241-1/+1
|\ | | | | Add `assert_nothing_raised` to make clear test case perpose
| * Add `assert_nothing_raised` to make clear test case perposeyui-knk2015-08-231-1/+1
| |
* | Remove test helper method to inside test methodyui-knk2015-08-231-5/+1
|/ | | | | | Remove `MigrationTest#connection` and write `ActiveRecord::Base.connection` directly to test, because `MigrationTest#connection` is only used in `test_migration_instance_has_connection`.
* Closes rails/rails#18864: Renaming transactional fixtures to transactional testsBrandon Weiss2015-03-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | I’m renaming all instances of `use_transcational_fixtures` to `use_transactional_tests` and “transactional fixtures” to “transactional tests”. I’m deprecating `use_transactional_fixtures=`. So anyone who is explicitly setting this will get a warning telling them to use `use_transactional_tests=` instead. I’m maintaining backwards compatibility—both forms will work. `use_transactional_tests` will check to see if `use_transactional_fixtures` is set and use that, otherwise it will use itself. But because `use_transactional_tests` is a class attribute (created with `class_attribute`) this requires a little bit of hoop jumping. The writer method that `class_attribute` generates defines a new reader method that return the value being set. Which means we can’t set the default of `true` using `use_transactional_tests=` as was done previously because that won’t take into account anyone using `use_transactional_fixtures`. Instead I defined the reader method manually and it checks `use_transactional_fixtures`. If it was set then it should be used, otherwise it should return the default, which is `true`. If someone uses `use_transactional_tests=` then it will overwrite the backwards-compatible method with whatever they set.
* Error message testing fixFranky W2015-02-201-1/+3
| | | | | | | | | The testing of error messages have been implemented wrongly a few times. This is an attempt to fix it. For example, some of these test should have failed with the new code. The reason they are not failling with the new string is the fact they were not being tested beforehand.
* pg tests, be clear about the missing type that causes a test skip.Yves Senn2015-02-121-8/+2
| | | | Also removed some cruft in the `setup` and `teardown` methods.
* tests, remove unused requires.Yves Senn2015-02-121-1/+0
| | | | | | "active_support/testing/stream" is already required in `test_case.rb`. Furthermore the test "test/cases/migration_test.rb" could no longer be executed directly.
* Allow a symbol to be passed to `attribute`, in place of a type objectSean Griffin2015-02-061-2/+2
| | | | | | | | | | | | | | | | | | The same is not true of `define_attribute`, which is meant to be the low level no-magic API that sits underneath. The differences between the two APIs are: - `attribute` - Lazy (the attribute will be defined after the schema has loaded) - Allows either a type object or a symbol - `define_attribute` - Runs immediately (might get trampled by schema loading) - Requires a type object This was the last blocker in terms of public interface requirements originally discussed for this feature back in May. All the implementation blockers have been cleared, so this feature is probably ready for release (pending one more look-over by me).
* Merge pull request #18526 from vipulnsward/add-silence-streamRafael Mendonça França2015-02-051-19/+3
|\ | | | | Extracted silence_stream method to new module in activesupport/testing
| * - Extracted silence_stream method to new module in activesupport/testing.Vipul A M2015-01-201-19/+3
| | | | | | | | | | | | | | | | | | | | | | | | - Added include for the same in ActiveSupport::Test. - Removed occurrences of silence_stream being used elsewhere. - Reordered activesupport testcase requires alphabetically. - Removed require of silence stream from test_case - Moved quietly method to stream helper - Moved capture output to stream helper module and setup requires for the same elsewhere
* | Attribute assignment and type casting has nothing to do with columnsSean Griffin2015-01-311-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It's finally finished!!!!!!! The reason the Attributes API was kept private in 4.2 was due to some publicly visible implementation details. It was previously implemented by overloading `columns` and `columns_hash`, to make them return column objects which were modified with the attribute information. This meant that those methods LIED! We didn't change the database schema. We changed the attribute information on the class. That is wrong! It should be the other way around, where schema loading just calls the attributes API for you. And now it does! Yes, this means that there is nothing that happens in automatic schema loading that you couldn't manually do yourself. (There's still some funky cases where we hit the connection adapter that I need to handle, before we can turn off automatic schema detection entirely.) There were a few weird test failures caused by this that had to be fixed. The main source came from the fact that the attribute methods are now defined in terms of `attribute_names`, which has a clause like `return [] unless table_exists?`. I don't *think* this is an issue, since the only place this caused failures were in a fake adapter which didn't override `table_exists?`. Additionally, there were a few cases where tests were failing because a migration was run, but the model was not reloaded. I'm not sure why these started failing from this change, I might need to clear an additional cache in `reload_schema_from_cache`. Again, since this is not normal usage, and it's expected that `reset_column_information` will be called after the table is modified, I don't think it's a problem. Still, test failures that were unrelated to the change are worrying, and I need to dig into them further. Finally, I spent a lot of time debugging issues with the mutex used in `define_attribute_methods`. I think we can just remove that method entirely, and define the attribute methods *manually* in the call to `define_attribute`, which would simplify the code *tremendously*. Ok. now to make this damn thing public, and work on moving it up to Active Model.
* | tests, use `drop_table if_exists: true` in our test suite.Yves Senn2015-01-201-1/+1
|/
* Use IO::NULL alwaysNobuyoshi Nakada2015-01-101-1/+1
|
* Remove deprecated methods at `Kernel`.Rafael Mendonça França2015-01-041-0/+10
| | | | `silence_stderr`, `silence_stream`, `capture` and `quietly`.
* Build fix when running in isolationArun Agrawal2014-11-141-0/+1
| | | | | `Computer` class needs to be require See #17217 for more details
* Load test schema even if there are no migrationsSean Griffin2014-10-311-0/+13
| | | | Fixes #17170
* Treat strings greater than int max value as out of rangeSean Griffin2014-10-311-1/+0
| | | | | | | | | | | Sufficiently large integers cause `find` and `find_by` to raise `StatementInvalid` instead of `RecordNotFound` or just returning `nil`. Given that we can't cast to `nil` for `Integer` like we would with junk data for other types, we raise a `RangeError` instead, and rescue in places where it would be highly unexpected to get an exception from casting. Fixes #17380
* MySQL: skip GTID-unsafe statement tests when enforce_gtid_consistency is enabledJeremy Kemper2014-09-011-17/+19
|
* MigrationTest doesn't need to be verbose anymoreAkira Matsuda2014-08-291-1/+1
|
* No tests are dealing with ActiveRecord::Migration.message_count here anymoreAkira Matsuda2014-08-291-1/+0
|
* Reset ActiveRecord::Migration.verbose to the value beforeAkira Matsuda2014-08-291-1/+3
|
* Drop schema_migrations table only when existsAkira Matsuda2014-08-201-1/+1
|
* Merge pull request #16349 from jmcnevin/masterRafael Mendonça França2014-08-191-0/+15
|\ | | | | Correctly determine if migration is needed.
| * Correctly determine if migration is needed.Jeremy McNevin2014-08-131-0/+15
| | | | | | | | | | | | | | 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.
* | Change the default `null` value for timestampsSean Griffin2014-08-121-1/+1
|/ | | | | | | As per discussion, this changes the model generators to specify `null: false` for timestamp columns. A warning is now emitted if `timestamps` is called without a `null` option specified, so we can safely change the behavior when no option is specified in Rails 5.
* build fix, remove not null constraint.Yves Senn2014-07-221-1/+1
| | | | | | | | | | | The fixtures are still in play, adding a new column without a default and `null: true` is not possible. This reverts back to leaking global state, as our `schema.rb` adds the `null: false` constraint on this field. A future solution would be to make the `migration_test.rb` run independent of fixture tables. This way we can simply drop the state after test execution, without worrying about side effects. /cc @zuhao
* Remove length limit that results failure in other tests.Zuhao Wan2014-07-221-1/+1
|
* Keep quietly and capture undeprecated on your suiteRafael Mendonça França2014-07-151-0/+10
|
* Don't type cast the default on the columnSean Griffin2014-06-171-1/+1
| | | | | | | If we want to have type decorators mess with the attribute, but not the column, we need to stop type casting on the column. Where possible, we changed the tests to test the value of `column_defaults`, which is public API. `Column#default` is not.
* Rename `property` to `attribute`Sean Griffin2014-06-071-3/+3
| | | | For consistency with https://github.com/rails/rails/pull/15557
* Remove deprecated method ActiveRecord::Migrator.proper_table_nameAkshay Vishnoi2014-06-051-41/+0
|
* Silence deprecation warning in testSean Griffin2014-05-271-0/+3
| | | | Missed a case that only occured for mysql/mysql2
* Deprecate decimal columns being automatically treated as integersSean Griffin2014-05-271-1/+4
| | | | | | With ActiveRecord::Properties, we now have a reasonable path for users to continue to keep this behavior if they want it. This is an edge case that has added a lot of complexity to the code base.
* Use teardown helper method.Guo Xiang Tan2014-03-141-2/+2
| | | | | | | | Follow-Up to https://github.com/rails/rails/pull/14348 Ensure that SQLCounter.clear_log is called after each test. This is a step to prevent side effects when running tests. This will allow us to run them in random order.
* we have `with_env_tz` as global test helper. Remove duplicate.Yves Senn2014-01-161-7/+0
|
* isolate class attribute assignment in `migration_test.rb`Yves Senn2014-01-161-22/+33
| | | | | | | | This makes the tests inside `migration_test.rb` order independent. The assignments to `Reminder.table_name_prefix` and `Reminder.table_name_suffix` previously leaked and had impact on following test cases. This patch isolates the assignments on a throw-away subclass.
* activerecord: Initialize Migration with version from MigrationProxy.Dylan Thacker-Smith2014-01-061-0/+4
|
* support creating temporary tables from queriesCody Cutrer2013-12-141-0/+26
| | | | | also override drop_table in AbstractMySQLAdapter to properly drop temporary tables without committing the transaction
* Get rid of hack for freezing time on AR testsCarlos Antonio da Silva2013-12-121-5/+5
| | | | | We can now make use of the existent #travel/#travel_to helper methods added to AS test case and available in all tests.
* test should clean up after themselvesAaron Patterson2013-11-151-0/+3
|
* Remove more skipRafael Mendonça França2013-11-081-2/+0
|
* Don't skip tests if we don't need to.Rafael Mendonça França2013-11-081-100/+92
| | | | | | | We can conditional define the tests depending on the adapter or connection. Lets keep the skip for fail tests that need to be fixed.
* Warnings removed for ruby trunkArun Agrawal2013-11-011-19/+19
| | | Same as 4d4ff531b8807ee88a3fc46875c7e76f613956fb
* added schema_migrations_table_name to ActiveRecord::Base in order that the ↵Jerad Phelps2013-10-271-1/+10
| | | | | | | | | | | | | | | | | | | | name of the schema migrations table can be configured. consolidated test_schema_migrations_table_name tests Added changelog entry edited changelog removed commented lines removed reader ensure the schema migrations table is reset at end of test added entry to configuration guide guides typo and changelog order
* Adding deprecation assertions for proper_table_name.wangjohn2013-08-241-7/+21
| | | | This prevents deprecation warnings from popping up.
* Making proper_table_name take in options.wangjohn2013-08-221-1/+28
| | | | | | | | | | | The options will specify the prefix and the suffix. Also, I'm moving the method to be an instance method on the +Migration+ instance. This makes more sense than being a class method on the +Migrator+ class because the only place that uses it is on a +Migration+ instance (in a method_missing hook). The logic for the Migrator shouldn't be doing any work to calculate the table name, it should be the Migration itself. Also made some small indentation fixes.
* Revert "fix order dependent test related to migration"Akira Matsuda2013-07-291-4/+0
| | | | | | This reverts commit 10259c3e906da2191ef0d43cd664a3b5504d9f8c. reason: this causes rake test_mysql and test_mysql2 fail