aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
Commit message (Collapse)AuthorAgeFilesLines
* Refactor `create_table`'s options separationRyuta Kamizono2019-06-031-2/+1
| | | | | | | | `create_table` and `t.column` have the same named options (e.g. `:comment`, `:primary_key`), so it should be separated table options from column options. Related #36373.
* Adding type option example to the documentation [ci skip] (#35917)Roberto Miranda2019-04-101-0/+1
| | | | | | | | | | | | * Adding type option example to the documentation [ci skip] It was hard for me looking https://api.rubyonrails.org/ to find that there was a type option. Adding this to the doc would be helpful especially for application with old tables where the references are still an integer not bigint * Update activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb Co-Authored-By: robertomiranda <rjmaltamar@gmail.com>
* Allow `remove_foreign_key` with both `to_table` and `options`Ryuta Kamizono2019-03-061-7/+3
| | | | | | | 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`.
* Address "warning: in `column': the last argument was passed as a single Hash"Ryuta Kamizono2019-02-211-3/+3
|
* 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-111-1/+1
| | | | | | | | | | | | 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-4/+1
|
* Merge pull request #35203 from chiastolite/add_column_without_column_namesRyuta Kamizono2019-02-101-0/+1
|\ | | | | | | Do not allow to add column without column name
| * Do not allow to add column without column nameHiroyuki Morita2019-02-101-0/+1
|/
* Refactor to extract defining column methods as `define_column_methods`Ryuta Kamizono2019-02-091-21/+23
| | | | | It makes to ease to handle all short-hand methods (e.g. validates arguments etc).
* Merge pull request #35105 from olivierlacan/document-table-foreign-keyGannon McGibbon2019-02-021-1/+2
|\ | | | | Hint at advanced options for foreign_key
| * Hint at advanced options for foreign_keyOlivier Lacan2019-01-301-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | We sometimes display simple examples of additional parameters that can be supplied to table-wise methods like these and I found it particularly difficult to figure out which options `t.foreign_key` accepts without drilling very deep into the specific SchemaStatements docs. Since it's relatively common to create foreign keys with custom column names or primary keys, it seems like this should help quite a few people. [ci skip]
* | Remove unused attr_writers `visitor` and `indexes`Ryuta Kamizono2019-02-011-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I deprecated two unused attr_writers `visitor` and `indexes` at 8056fe0 and f4bc364 conservatively, since those are accidentaly exposed in the docs. https://api.rubyonrails.org/v5.2/classes/ActiveRecord/ConnectionAdapters/AbstractAdapter.html https://api.rubyonrails.org/v5.2/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html But I've found that `view_renderer` attr_writer is removed without deprecation at #35093, that is also exposed in the doc. https://api.rubyonrails.org/v5.2/classes/ActionView/Base.html I'd like to also remove the deprecated attr_writers since I think that removing `visitor` and `indexes` attr_writers is as safe as removing `view_renderer` attr_writer.
* | Make `t.timestamps` with precision by defaultRyuta Kamizono2019-01-261-0/+6
|/
* Deprecate `t.indexes = [...]` which is not by designRyuta Kamizono2018-11-091-2/+5
| | | | Use `t.index ...` instead.
* Refactor to initialize `TableDefinition` by kwargsRyuta Kamizono2018-11-091-1/+9
|
* Add an :if_not_exists option to create_tablefatkodima2018-11-081-2/+3
| | | | [fatkodima & Stefan Kanev]
* Remove and flip `index: true` for `references` in the doc [ci skip]Ryuta Kamizono2018-10-171-2/+2
| | | | Follow up #32146.
* Index option added for change_table migrationsMehmet Emin INAC2018-09-221-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Migrations will raise an exception if there are multiple column definitions ↵Federico Martinez2018-06-011-2/+6
| | | | (same name).
* Remove :nodoc: from the methods which is added the doc [ci skip]Ryuta Kamizono2018-05-151-4/+4
| | | | Follow up of #19171 and #26825.
* Add available transformations to docs [ci skip]wata_mac2018-05-131-0/+3
| | | | `foreign_key`, `json` and `virtual` are also available.
* Move fk_ignore_pattern from config.active_record to SchemaDumperDavid Stosik2018-03-221-1/+1
| | | | | This makes more sense, as the foreign key ignore pattern is only used by the schema dumper.
* Expose foreign key name ignore pattern in configurationDavid Stosik2018-03-191-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | When dumping the database schema, Rails will dump foreign key names only if those names were not generate by Rails. Currently this is determined by checking if the foreign key name is `fk_rails_` followed by a 10-character hash. At [Cookpad](https://github.com/cookpad), we use [Departure](https://github.com/departurerb/departure) (Percona's pt-online-schema-change runner for ActiveRecord migrations) to run migrations. Often, `pt-osc` will make a copy of a table in order to run a long migration without blocking it. In this copy process, foreign keys are copied too, but [their name is prefixed with an underscore to prevent name collision ](https://www.percona.com/doc/percona-toolkit/LATEST/pt-online-schema-change.html#cmdoption-pt-online-schema-change-alter-foreign-keys-method). In the process described above, we often end up with a development database that contains foreign keys which name starts with `_fk_rails_`. That name does not match the ignore pattern, so next time Rails dumps the database schema (eg. when running `rake db:migrate`), our `db/schema.rb` file ends up containing those unwanted foreign key names. This also produces an unwanted git diff that we'd prefer not to commit. In this PR, I'd like to suggest a way to expose the foreign key name ignore pattern to the Rails configuration, so that individual projects can decide on a different pattern of foreign keys that will not get their names dumped in `schema.rb`.
* Rails 6 requires Ruby 2.3+Jeremy Daer2018-02-171-6/+1
|
* Emulate JSON types for SQLite3 adapter (#29664)Ryuta Kamizono2017-12-031-0/+1
| | | | | Actually SQLite3 doesn't have JSON storage class (so it is stored as a TEXT like Date and Time). But emulating JSON types is convinient for making database agnostic migrations.
* Refactor `length`, `order`, and `opclass` index options dumpingRyuta Kamizono2017-12-031-5/+14
|
* Add support for invalid foreign keys in PostgresTravis Hunter2017-12-011-0/+5
| | | | Add validate_constraint and update naming
* Add support for PostgreSQL operator classes to add_indexGreg Navis2017-11-301-1/+3
| | | | | | | | | | | | 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}
* Extract `integer_like_primary_key_type` to ease to handle it for adaptersRyuta Kamizono2017-09-251-0/+7
|
* Move integer-like primary key normalization to `new_column_definition`Ryuta Kamizono2017-09-231-0/+4
| | | | | | Currently the normalization only exists in `primary_key` shorthand. It should be moved to `new_column_definition` to also affect to `add_column` with primary key.
* `add_reference` should respect column position for both reference id and ↵Ryuta Kamizono2017-09-011-1/+1
| | | | | | type columns Fixes #30496.
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* 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.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Both reference id and type should be `NOT NULL` if `null: false` is specifiedRyuta Kamizono2017-05-191-1/+1
| | | | | | This is a regression due to #28282. Fixes #29136.
* Fix the doc on the `IndexDefinition` [ci skip]Ryuta Kamizono2017-04-171-1/+1
| | | | Since 1a92ae83 all `indexes` methods are under the `SchemaStatements`.
* Refactor `indexes` things in connection adaptersRyuta Kamizono2017-04-161-1/+26
| | | | | | | * Use keyword arguments in `IndexDefinition` to ease to ignore unused options and to avoid to initialize incorrect empty value. * Place it in `SchemaStatements` for consistency. * And tiny tweaks.
* Don't share `options` with a reference type columnRyuta Kamizono2017-03-041-7/+3
| | | | | | | | | Sharing `options` causes some unexpected behavior. If `limit: 2` is specified, this means that 2 bytes integer for a reference id column and 2 chars string for a reference type column. Another example, if `unsigned: true` is specified, this means that unsigned integer for a reference id column, but a invalid option for a reference type column. So `options` should not be shared with a reference type column.
* Refactor `ColumnDefinition` to contain `options` hashRyuta Kamizono2017-02-091-20/+20
| | | | | | Column options are passed as an hash args then used as `options` hash in `add_column_options!`. Converting args to attributes is inconvinient for using options as an hash.
* `primary_key` and `references` columns should be identical typeRyuta Kamizono2017-02-071-6/+4
| | | | | | | | Follow up to #26266. The default type of `primary_key` and `references` were changed to `bigint` since #26266. But legacy migration and sqlite3 adapter should keep its previous behavior.
* Virtual/generated column support for MySQL 5.7.5+ and MariaDB 5.2.0+Ryuta Kamizono2017-02-011-1/+3
| | | | | | | | | | | | | | | | | | | MySQL generated columns: https://dev.mysql.com/doc/refman/5.7/en/create-table-generated-columns.html MariaDB virtual columns: https://mariadb.com/kb/en/mariadb/virtual-computed-columns/ Declare virtual columns with `t.virtual name, type: …, as: "expression"`. Pass `stored: true` to persist the generated value (false by default). Example: create_table :generated_columns do |t| t.string :name t.virtual :upper_name, type: :string, as: "UPPER(name)" t.virtual :name_length, type: :integer, as: "LENGTH(name)", stored: true t.index :name_length # May be indexed, too! end Closes #22589
* class Foo < Struct.new(:x) creates an extra unneeded anonymous classAkira Matsuda2017-01-131-10/+6
| | | | because Struct.new returns a Class, we just can give it a name and use it directly without inheriting from it
* Describe what we are protectingAkira Matsuda2016-12-231-0/+2
|
* Change MySQL and Postgresql to use Bigint primary keysJon McCartie2016-12-051-1/+1
|
* Fix indentation of code examplesOrhan Toy2016-10-191-4/+4
| | | | This commit fixes the generated HTML of the two code examples.
* Added nil case handling to allow rollback migration in case oftravis.h.oneill@gmail.com2016-08-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | invalid column type /activerecord/lib/active_record/connection_adapters /abstract/schema_definitions.rb:306 type = type.to_sym Changed to the following to handle nil case: type = type.to_sym if type Added regression test for this case: /activerecord/test/cases/migration_test.rb:554 if current_adapter?(:SQLite3Adapter) def test_allows_sqlite3_rollback_on_invalid_column_type Person.connection.create_table :something, force: true do |t| t.column :number, :integer t.column :name, :string t.column :foo, :bar end assert Person.connection.column_exists?(:something, :foo) assert_nothing_raised { Person.connection.remove_column :something, :foo, :bar } assert !Person.connection.column_exists?(:something, :foo) assert Person.connection.column_exists?(:something, :name) assert Person.connection.column_exists?(:something, :number) ensure Person.connection.drop_table :something, if_exists: true end end
* Merge pull request #26151 from kamipo/avoid_to_allow_unused_splat_argsRafael França2016-08-161-3/+1
|\ | | | | Avoid to allow unused splat args for `t.timestamps` in `create_table`
| * Avoid to allow unused splat args for `t.timestamps` in `create_table`Ryuta Kamizono2016-08-141-3/+1
| | | | | | | | | | | | Unfortunately `t.timestamps` in `create_table` allows unused splat args. But the same one in `change_table` does not allow them. This commit fixes the inconsistent behavior.
* | Merge pull request #26019 from agrobbin/schema-load-unique-column-indicesRafael França2016-08-161-2/+2
|\ \ | |/ |/| Support multiple indexes on the same column when loading the schema