aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
Commit message (Collapse)AuthorAgeFilesLines
* Refactor migration to move migrations paths to connectioneileencodes2018-01-181-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Extract duplicated index column options normalization as ↵Ryuta Kamizono2017-12-031-9/+10
| | | | | | | `options_for_index_columns` And placed `add_options_for_index_columns` in `schema_statements.rb` consistently to ease to find related code.
* Refactor `length`, `order`, and `opclass` index options dumpingRyuta Kamizono2017-12-031-1/+1
|
* Merge pull request #31230 from dinahshi/postgresql_extract_sqlMatthew Draper2017-12-031-1/+15
|\ | | | | Extract sql fragment generators from PostgreSQL adapter
| * Extract sql fragment generators for alter table from PostgreSQL adapterDinah Shi2017-12-021-1/+15
| |
* | Add support for invalid foreign keys in PostgresTravis Hunter2017-12-011-0/+2
| | | | | | | | Add validate_constraint and update naming
* | Remove unpaired `}` [ci skip]Ryuta Kamizono2017-12-011-2/+1
| |
* | Add support for PostgreSQL operator classes to add_indexGreg Navis2017-11-301-2/+26
|/ | | | | | | | | | | | Add support for specifying non-default operator classes in PostgreSQL indexes. An example CREATE INDEX query that becomes possible is: CREATE INDEX users_name ON users USING gist (name gist_trgm_ops); Previously it was possible to specify the `gist` index but not the custom operator class. The `add_index` call for the above query is: add_index :users, :name, using: :gist, opclasses: {name: :gist_trgm_ops}
* [ci skip]Update the documentation about the primary key typesuginoy2017-10-291-15/+15
| | | | | | Replace the primary key type `integer` in docs with `bigint`. ref #26266
* Remove deprecated argument `name` from `#indexes`Rafael Mendonça França2017-10-231-1/+1
|
* Remove deprecated methods `initialize_schema_migrations_table` and ↵Rafael Mendonça França2017-10-231-10/+0
| | | | `initialize_internal_metadata_table`
* Remove deprecated argument `default` from `index_name_exists?`Rafael Mendonça França2017-10-231-6/+1
|
* [Active Record] require => require_relativeAkira Matsuda2017-10-211-1/+1
| | | | This basically reverts 9d4f79d3d394edb74fa2192e5d9ad7b09ce50c6d
* Express #change_column_comment as public apibogdanvlviv2017-10-041-1/+1
| | | | | Implemented by #22911 Related to #30677
* Preload digest/sha2 to avoid thread safe error.Francesco Rodriguez2017-09-251-1/+1
| | | | | | | | | | | | | | | | I got this error in production using Puma in multi-threaded mode: ``` RuntimeError: Digest::Base cannot be directly inherited in Ruby from active_support/security_utils.rb:23:in `variable_size_secure_compare' from active_support/security_utils.rb:23:in `hexdigest' from active_support/security_utils.rb:23:in `digest' ``` Looks like Digest uses const_missing to load Digest::SHA256 (https://github.com/ruby/ruby/blob/trunk/ext/digest/lib/digest.rb#L8) - https://bugs.ruby-lang.org/issues/9494 - https://github.com/ruby/ruby/commit/c02fa39463a0c6bf698b01bc610135604aca2ff4
* Add :comment option for add_column [ci skip]Yoshiyuki Kinjo2017-09-201-0/+2
|
* Clarify that bulk option is supported only by MySQL [ci skip]Prathamesh Sonpatki2017-08-291-0/+2
| | | | - Closes #30441
* Refactor `SchemaDumper` to make it possible to adapter specific customizationRyuta Kamizono2017-08-221-0/+4
| | | | | | | Currently `SchemaDumper` is only customizable for column options. But 3rd party connection adapters (oracle-enhanced etc) need to customizable for table or index dumping also. To make it possible, I introduced adapter specific `SchemaDumper` classes for that.
* [ci skip] Postgres --> PostgreSQLRyuta Kamizono2017-08-081-1/+1
|
* Clarify add_column limit documentationLisa Ugray2017-07-251-0/+1
| | | | | The limit option is ignored by PostgreSQL and may be ignored by 3rd party backends. Make this clear in the docs. Fixes #29922.
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Merge branch 'master' into require_relative_2017Xavier Noria2017-07-021-7/+7
|\
| * Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | | | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
| * Merge pull request #29540 from kirs/rubocop-frozen-stringMatthew Draper2017-07-021-0/+1
| |\ | | | | | | | | | Enforce frozen string in Rubocop
| | * Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
| | |
| * | Merge pull request #29506 from pat/frozen-string-literalsMatthew Draper2017-07-021-1/+1
| |\ \ | | | | | | | | | | | | Make ActiveSupport frozen-string-literal friendly.
| | * | Make ActiveRecord frozen string literal friendly.Pat Allan2017-06-201-1/+1
| | |/
| * / Don't cache queries for schema statementsRyuta Kamizono2017-06-301-6/+6
| |/ | | | | | | | | | | `test_middleware_caches` is sometimes failed since #29454. The failure is due to schema statements are affected by query caching. Bypassing query caching for schema statements to avoid the issue.
* / [Active Record] require => require_relativeAkira Matsuda2017-07-011-1/+1
|/
* Fix `dump_schema_information` with empty versionsRyuta Kamizono2017-06-151-1/+1
| | | | Fixes #29460.
* Remove `null_allowed` option from doc [ci skip]yuuji.yaginuma2017-06-101-2/+1
| | | | This option was added in b9fa354. But it does not seem to work.
* [ci skip] Add missing `be`Prathamesh Sonpatki2017-06-031-1/+1
|
* Merge pull request #29135 from ↵Eileen M. Uchitelle2017-06-021-0/+19
|\ | | | | | | | | Nerian/document_support_for_composite_primary_keys Document support for composite primary keys
| * Document support for composite primary keysNerian2017-05-181-0/+19
| |
* | [Foreign Key] Don't worry about the building identifier if name is already ↵Mohit Natoo2017-05-101-2/+3
|/ | | | present.
* Make internal methods to privateRyuta Kamizono2017-03-271-23/+46
|
* Remove duplicated `columns` definitionRyuta Kamizono2017-03-201-3/+5
|
* Merge pull request #28068 from kamipo/refactor_data_sourcesRafael França2017-03-131-2/+18
|\ | | | | Extract `data_source_sql` to refactor data source statements
| * Extract `data_source_sql` to refactor data source statementsRyuta Kamizono2017-02-201-2/+18
| |
* | Extract `SchemaMigration.all_versions`Ryuta Kamizono2017-03-061-2/+2
| | | | | | | | | | Use `SchemaMigration.all_versions` instead of `SchemaMigration.all.map(&:version)` to avoid to instantiate AR objects.
* | Remove useless `Migrator.schema_migrations_table_name`Ryuta Kamizono2017-03-051-2/+2
| | | | | | | | Simply use `SchemaMigration.table_name` instead.
* | Don't hide method that's been documented API since Rails 2.1Andrew White2017-03-041-3/+3
| |
* | Fix `rake db:schema:load` with subdirectoriesRyuta Kamizono2017-03-051-5/+4
| | | | | | | | | | | | | | | | Related #25174. `db:schema:load` doesn't work with subdirectories like previous `db:migrate:status`. `Migrator.migration_files` should be used in `assume_migrated_upto_version` to fix the issue.
* | `create_join_table` should respect `references` column typeRyuta Kamizono2017-02-281-7/+5
| | | | | | | | | | | | | | | | Follow up of #26266. The default type of `primary_key` and `references` were changed to `bigint` since #26266. But `create_join_table` column type is still `integer`. It should respect `references` column type.
* | Merge pull request #25285 from ↵Rafael França2017-02-231-0/+1
|\ \ | | | | | | | | | | | | kamipo/fix_remove_reference_to_multiple_foreign_keys_in_the_same_table Fix `remove_reference` to multiple foreign keys in the same table
| * | Fix `remove_reference` to multiple foreign keys in the same tableRyuta Kamizono2017-02-111-0/+1
| | |
* | | Correctly dump native timestamp types for MySQLRyuta Kamizono2017-02-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The native timestamp type in MySQL is different from datetime type. Internal representation of the timestamp type is UNIX time, This means that timestamp columns are affected by time zone. ``` > SET time_zone = '+00:00'; Query OK, 0 rows affected (0.00 sec) > INSERT INTO time_with_zone(ts,dt) VALUES (NOW(),NOW()); Query OK, 1 row affected (0.02 sec) > SELECT * FROM time_with_zone; +---------------------+---------------------+ | ts | dt | +---------------------+---------------------+ | 2016-02-07 22:11:44 | 2016-02-07 22:11:44 | +---------------------+---------------------+ 1 row in set (0.00 sec) > SET time_zone = '-08:00'; Query OK, 0 rows affected (0.00 sec) > SELECT * FROM time_with_zone; +---------------------+---------------------+ | ts | dt | +---------------------+---------------------+ | 2016-02-07 14:11:44 | 2016-02-07 22:11:44 | +---------------------+---------------------+ 1 row in set (0.00 sec) ```
* | | Improve `create_table force: true`Ryuta Kamizono2017-02-201-2/+2
| |/ |/| | | | | | | Extra `data_source_exists?(table_name)` is unneeded if `drop_table(table_name, if_exists: true)` directly.
* | Merge pull request #26655 from kamipo/fix_remove_expression_indexRafael França2017-02-131-12/+16
|\ \ | | | | | | Fix `remove_index` to be able to remove expression indexes
| * | Fix `remove_index` to be able to remove expression indexesRyuta Kamizono2016-12-251-12/+16
| | | | | | | | | | | | Fixes #26635, #26641.