aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/migration
Commit message (Collapse)AuthorAgeFilesLines
* Just inherit `ForeignKeyChangeColumnTest` for with prefix/suffix testsRyuta Kamizono2019-03-071-17/+5
|
* Allow `remove_foreign_key` with both `to_table` and `options`Ryuta Kamizono2019-03-061-0/+12
| | | | | | | Foreign keys could be created to the same table. So `remove_foreign_key :from_table, :to_table` is sometimes ambiguous. This allows `remove_foreign_key` to remove the select one on the same table with giving both `to_table` and `options`.
* Remove unnecessary `current_adapter?(:OracleAdapter)` for index lengthYasuo Honda2019-03-031-8/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Follow up #35455, there are two more test cases unnecessary `if current_adapter?(:OracleAdapter)` ```ruby $ ARCONN=oracle bin/test test/cases/associations/eager_test.rb -n test_include_has_many_using_primary_key Using oracle Run options: -n test_include_has_many_using_primary_key --seed 62842 . Finished in 50.280024s, 0.0199 runs/s, 0.0398 assertions/s. 1 runs, 2 assertions, 0 failures, 0 errors, 0 skips $ ``` ``` $ ARCONN=oracle bin/test test/cases/migration/index_test.rb -n test_add_index Using oracle Run options: -n test_add_index --seed 52034 . Finished in 13.152620s, 0.0760 runs/s, 0.0000 assertions/s. 1 runs, 0 assertions, 0 failures, 0 errors, 0 skips $ ```
* Oracle 12.2+ supports 128 byte identifier lengthYasuo Honda2019-03-031-10/+2
| | | | | | | | | | | | | | | | | | | | | ```ruby $ ARCONN=oracle bin/test test/cases/migration/columns_test.rb -n test_rename_column_with_multi_column_index ... snip ... F Failure: ActiveRecord::Migration::ColumnsTest#test_rename_column_with_multi_column_index [/home/yahonda/git/rails/activerecord/test/cases/migration/columns_test.rb:113]: --- expected +++ actual @@ -1 +1 @@ -["i_test_models_hat_style_size"] +["index_test_models_on_hat_style_and_size"] ``` Kind of reverting #9395 Refer https://github.com/rsim/oracle-enhanced/pull/1703
* Refactor `type_to_sql` to handle converting `limit` to `size` in itselfRyuta Kamizono2019-02-261-4/+2
| | | | | Also, improving an argument error message for `limit`, extracting around `type_to_sql` code into schema statements, and more exercise tests.
* Remove `NoForeignKeySupportTest` which is no longer reachedRyuta Kamizono2019-02-162-46/+0
| | | | Since #35212, foreign key feature is supported by all adapters.
* Add `remove_foreign_key` for `change_table`Ryuta Kamizono2019-02-111-0/+11
|
* SQLite3: Implement `add_foreign_key` and `remove_foreign_key`Ryuta Kamizono2019-02-113-15/+43
| | | | | | | | | | | | I implemented Foreign key create in `create_table` for SQLite3 at #24743. This follows #24743 to implement `add_foreign_key` and `remove_foreign_key`. Unfortunately SQLite3 has one limitation that `PRAGMA foreign_key_list(table-name)` doesn't have constraint name. So we couldn't implement find/remove foreign key by name for now. Fixes #35207. Closes #31343.
* More exercise table name prefix and suffix testsRyuta Kamizono2019-02-111-25/+81
|
* Merge pull request #35203 from chiastolite/add_column_without_column_namesRyuta Kamizono2019-02-101-0/+11
|\ | | | | | | Do not allow to add column without column name
| * Do not allow to add column without column nameHiroyuki Morita2019-02-101-0/+9
|/
* Make `t.timestamps` with precision by defaultRyuta Kamizono2019-01-261-0/+71
|
* Fix `t.timestamps` missing `null: false` in `change_table bulk: true`Ryuta Kamizono2019-01-261-0/+17
|
* Allow `column_exists?` giving options without typeRyuta Kamizono2019-01-261-6/+6
|
* Enable `Style/RedundantBegin` cop to avoid newly adding redundant begin blockRyuta Kamizono2018-12-211-16/+14
| | | | | | | | | | Currently we sometimes find a redundant begin block in code review (e.g. https://github.com/rails/rails/pull/33604#discussion_r209784205). I'd like to enable `Style/RedundantBegin` cop to avoid that, since rescue/else/ensure are allowed inside do/end blocks in Ruby 2.5 (https://bugs.ruby-lang.org/issues/12906), so we'd probably meets with that situation than before.
* Merge pull request #23593 from meinac/add_index_option_for_change_tableRyuta Kamizono2018-10-011-0/+8
|\ | | | | | | index option added for change_table migrations
| * Index option added for change_table migrationsMehmet Emin INAC2018-09-221-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In case if we want to add a column into the existing table with index on it, we have to add column and index in two seperate lines. With this feature we don't need to write an extra line to add index for column. We can just use `index` option. Old behaviour in action: ``` change_table(:languages) do |t| t.string :country_code t.index: :country_code end ``` New behaviour in action: ``` change_table(:languages) do |t| t.string :country_code, index: true end ``` Exactly same behaviour is already exist for `create_table` migrations.
* | Fix `transaction` reverting for migrationsfatkodima2018-09-262-0/+24
| | | | | | | | [fatkodima & David Verhasselt]
* | Change the empty block style to have space inside of the blockRafael Mendonça França2018-09-252-5/+5
|/
* SQLite3: Fix rename reference column not to lose foreign key constraintRyuta Kamizono2018-08-201-0/+16
| | | | Fixes #33520.
* Ensure `foreign_keys` assertions after alter tableRyuta Kamizono2018-08-191-1/+5
| | | | | If `foreign_keys` is fetched before alter table, it couldn't notice whether foreign keys are broken or not after alter table.
* Merge pull request #33585 from yahonda/diag33520Ryuta Kamizono2018-08-161-0/+13
|\ | | | | | | SQLite3 adapter `alter_table` method restores foreign keys
| * SQLite3 adapter `alter_table` method restores foreign keysYasuo Honda2018-08-111-0/+13
| | | | | | | | Related to #33520
* | Follow up #33530bogdanvlviv2018-08-151-0/+5
| | | | | | | | | | | | | | | | | | - Move changelog entry of #33530 up in order to preserve the chronology since we always add new entries on the top of a changelog file. - Clarify the changelog entry - Clarify the docs of remove_foreign_key - Ensure reversible of `remove_foreign_key` with `:primary_key` and `:to_table` options.
* | Allow `to_table` in `invert_remove_foreign_key`Rich2018-08-141-0/+8
|/ | | | | | | | | | | | remove_foreign_key supports - remove_foreign_key :accounts, :branches - remove_foreign_key :accounts, to_table: :branches but the second one is not reversible. This branch is to fix and allow second one to be reversible. [Nikolay Epifanov, Rich Chen]
* Migrations will raise an exception if there are multiple column definitions ↵Federico Martinez2018-06-011-0/+11
| | | | (same name).
* Disable foreign keys during `alter_table` for sqlite3 adapterYasuo Honda2018-05-221-0/+46
| | | | | | | | | | | | | | | | | | | | | | | | | Unlike other databases, changing SQLite3 table definitions need to create a temporary table. While changing table operations, the original table needs dropped which caused `SQLite3::ConstraintException: FOREIGN KEY constraint failed` if the table is referenced by foreign keys. This pull request disables foreign keys by `disable_referential_integrity`. Also `disable_referential_integrity` method needs to execute `defer_foreign_keys = ON` to defer re-enabling foreign keys until the transaction is committed. https://www.sqlite.org/pragma.html#pragma_defer_foreign_keys Fixes #31988 - This `defer_foreign_keys = ON` has been supported since SQLite 3.8.0 https://www.sqlite.org/releaselog/3_8_0.html and Rails 6 requires SQLite 3.8 #32923 now - <Models>.reset_column_information added to address `ActiveModel::UnknownAttributeError` ``` Error: ActiveRecord::Migration::ForeignKeyChangeColumnTest#test_change_column_of_parent_table: ActiveModel::UnknownAttributeError: unknown attribute 'name' for ActiveRecord::Migration::ForeignKeyChangeColumnTest::Post. ```
* Fix `CustomCops/AssertNot` to allow it to have failure messageRyuta Kamizono2018-05-131-1/+1
| | | | Follow up of #32605.
* More exercise `test_remove_named_index`Ryuta Kamizono2018-05-021-1/+4
| | | | | Ensure that do not accidentally remove an index of different definitions.
* Replace `assert !` with `assert_not`Daniel Colson2018-04-193-13/+13
| | | | | This autocorrects the violations after adding a custom cop in 3305c78dcd.
* Move fk_ignore_pattern from config.active_record to SchemaDumperDavid Stosik2018-03-221-1/+4
| | | | | This makes more sense, as the foreign key ignore pattern is only used by the schema dumper.
* Test config.active_record.fk_ignore_patternDavid Stosik2018-03-201-0/+8
|
* Remove usage of strip_heredoc in the framework in favor of <<~Rafael Mendonça França2018-02-161-1/+1
| | | | | Some places we can't remove because Ruby still don't have a method equivalent to strip_heredoc to be called in an already existent string.
* Use assert_predicate and assert_not_predicateDaniel Colson2018-01-255-25/+25
|
* Change refute to assert_notDaniel Colson2018-01-252-7/+7
|
* Use respond_to test helpersDaniel Colson2018-01-251-2/+2
|
* Refactor migration to move migrations paths to connectioneileencodes2018-01-181-25/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rails has some support for multiple databases but it can be hard to handle migrations with those. The easiest way to implement multiple databases is to contain migrations into their own folder ("db/migrate" for the primary db and "db/seconddb_migrate" for the second db). Without this you would need to write code that allowed you to switch connections in migrations. I can tell you from experience that is not a fun way to implement multiple databases. This refactoring is a pre-requisite for implementing other features related to parallel testing and improved handling for multiple databases. The refactoring here moves the class methods from the `Migrator` class into it's own new class `MigrationContext`. The goal was to move the `migrations_paths` method off of the `Migrator` class and onto the connection. This allows users to do the following in their `database.yml`: ``` development: adapter: mysql2 username: root password: development_seconddb: adapter: mysql2 username: root password: migrations_paths: "db/second_db_migrate" ``` Migrations for the `seconddb` can now be store in the `db/second_db_migrate` directory. Migrations for the primary database are stored in `db/migrate`". The refactoring here drastically reduces the internal API for migrations since we don't need to pass `migrations_paths` around to every single method. Additionally this change does not require any Rails applications to make changes unless they want to use the new public API. All of the class methods from the `Migrator` class were `nodoc`'d except for the `migrations_paths` and `migrations_path` getter/setters respectively.
* SQLite: Add more test cases for adding primary keyRyuta Kamizono2017-12-261-58/+48
|
* Fix `add_column` with :primary_key type compatibility for SQLitefatkodima2017-12-251-0/+19
|
* Suppress `warning: BigDecimal.new is deprecated` in activerecordYasuo Honda2017-12-131-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `BigDecimal.new` has been deprecated in BigDecimal 1.3.3 which will be a default for Ruby 2.5. Refer https://github.com/ruby/bigdecimal/commit/533737338db915b00dc7168c3602e4b462b23503 ``` $ cd rails/activerecord/ $ git grep -l BigDecimal.new | grep \.rb | xargs sed -i -e "s/BigDecimal.new/BigDecimal/g" ``` - Changes made only to Active Record. Will apply the same change to other module once this commit is merged. - The following deprecation has not been addressed because it has been reported at `ActiveRecord::Result.new`. `ActiveRecord::Result.ancestors` did not show `BigDecimal`. * Not addressed ```ruby /path/to/rails/activerecord/lib/active_record/connection_adapters/mysql/database_statements.rb:34: warning: BigDecimal.new is deprecated ``` * database_statements.rb:34 ```ruby ActiveRecord::Result.new(result.fields, result.to_a) if result ``` * ActiveRecord::Result.ancestors ```ruby [ActiveRecord::Result, Enumerable, ActiveSupport::ToJsonWithActiveSupportEncoder, Object, Metaclass::ObjectMethods, Mocha::ObjectMethods, PP::ObjectMixin, ActiveSupport::Dependencies::Loadable, ActiveSupport::Tryable, JSON::Ext::Generator::GeneratorMethods::Object, Kernel, BasicObject] ``` This commit has been tested with these Ruby and BigDecimal versions - ruby 2.5 and bigdecimal 1.3.3 ``` $ ruby -v ruby 2.5.0dev (2017-12-14 trunk 61217) [x86_64-linux] $ gem list |grep bigdecimal bigdecimal (default: 1.3.3, default: 1.3.2) ``` - ruby 2.4 and bigdecimal 1.3.0 ``` $ ruby -v ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux-gnu] $ gem list |grep bigdecimal bigdecimal (default: 1.3.0) ``` - ruby 2.3 and bigdecimal 1.2.8 ``` $ ruby -v ruby 2.3.5p376 (2017-09-14 revision 59905) [x86_64-linux] $ gem list |grep -i bigdecimal bigdecimal (1.2.8) ``` - ruby 2.2 and bigdecimal 1.2.6 ``` $ ruby -v ruby 2.2.8p477 (2017-09-14 revision 59906) [x86_64-linux] $ gem list |grep bigdecimal bigdecimal (1.2.6) ```
* `change_column_default` should be executed after type changingRyuta Kamizono2017-12-031-2/+2
| | | | | | | | | | | | | | | | | | | | If do not execute a type changing first, filling in default value may be failed. ``` % ARCONN=postgresql be ruby -w -Itest test/cases/migration/compatibility_test.rb -n test_legacy_change_column_with_null_executes_update Using postgresql Run options: -n test_legacy_change_column_with_null_executes_update --seed 20459 E Error: ActiveRecord::Migration::CompatibilityTest#test_legacy_change_column_with_null_executes_update: StandardError: An error has occurred, this and all later migrations canceled: PG::StringDataRightTruncation: ERROR: value too long for type character varying(5) : UPDATE "testings" SET "foo"='foobar' WHERE "foo" IS NULL ```
* Fix `s/klass.connection/connection/`Ryuta Kamizono2017-12-031-1/+1
| | | | `klass` has removed in 5358f2b67bd6fb12d708527a4a70dcab65513c5e.
* Fix `test_add_column_with_timestamp_type` failureRyuta Kamizono2017-12-032-7/+8
| | | | | | | This test failed due to dirty schema cache. It is needed to call `clear_cache!` when using same named table with different definition. https://travis-ci.org/rails/rails/jobs/310627767#L769-L772
* Fix warning: assigned but unused variable - tRyuta Kamizono2017-12-031-1/+1
|
* Merge pull request #31230 from dinahshi/postgresql_extract_sqlMatthew Draper2017-12-031-0/+17
|\ | | | | Extract sql fragment generators from PostgreSQL adapter
| * Extract sql fragment generators for alter table from PostgreSQL adapterDinah Shi2017-12-021-0/+17
| |
* | Add support for invalid foreign keys in PostgresTravis Hunter2017-12-011-0/+68
|/ | | | Add validate_constraint and update naming
* Remove deprecated argument `default` from `index_name_exists?`Rafael Mendonça França2017-10-231-4/+2
|
* Should test `LegacyPrimaryKeyTest` to both `V5_0` and `V4_2`Ryuta Kamizono2017-10-181-15/+34
|
* compatibility - use int instead of bigintpavel2017-10-181-0/+3
|