aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
Commit message (Collapse)AuthorAgeFilesLines
* 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
| * support multiple indexes on the same column when loading the schemaAlex Robbin2016-08-021-2/+2
| |
* | applies remaining conventions across the projectXavier Noria2016-08-061-1/+0
| |
* | normalizes indentation and whitespace across the projectXavier Noria2016-08-061-41/+41
| |
* | applies new string literal convention in activerecord/libXavier Noria2016-08-061-1/+1
|/ | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Fix failing testsSean Griffin2016-06-021-4/+5
| | | | | | | | | | | | | | | | | | | Currently CI is broken due to 56a61e0 and c4cb686. This occurred because the failures are not present on SQLite which is what I normally run locally before pushing. The optimizations to our YAML size were dropping mutations, as `with_type` didn't set the previous value if it'd already been read (that method was never really designed to be used with values on individual objects, it was previously only used for defaults). I'm questioning whether there's a better place to be handling the exclusion of the type, but this will fix the failing build. Additionally, there was a bug in `remove_foreign_key` if you passed it an options hash containing `to_table`. This now occurs whenever removing a reference, as we always normalize to a hash. [Sean Griffin & Ryuta Kamizono]
* `foreign_key` respects `table_name_prefix` and `table_name_suffix`Ryuta Kamizono2016-04-191-0/+3
|
* Database comments: switch to keyword args for new table optionsJeremy Daer2016-04-181-1/+1
| | | | | | * Switch to keyword args where we can without breaking compat. * Use add_table_options! for :options, too. * Some code polish.
* Add support for specifying comments for tables, columns, and indexes.Andrey Novikov2016-04-161-4/+6
| | | | | | | | | | | | | Comments are specified in migrations, stored in database itself (in its schema), and dumped into db/schema.rb file. This allows to generate good documentation and explain columns and tables' purpose to everyone from new developers to database administrators. For PostgreSQL and MySQL only. SQLite does not support comments at the moment. See docs for PostgreSQL: http://www.postgresql.org/docs/current/static/sql-comment.html See docs for MySQL: http://dev.mysql.com/doc/refman/5.7/en/create-table.html
* Let t.foreign_key use the same `to_table` twiceGeorge Millo2016-02-151-2/+2
| | | | | | | | | | | | | | | | | | | | | Previously if you used `t.foreign_key` twice within the same `create_table` block using the same `to_table`, all statements except the final one would fail silently. For example, the following code: def change create_table :flights do |t| t.integer :from_id, index: true, null: false t.integer :to_id, index: true, null: false t.foreign_key :airports, column: :from_id t.foreign_key :airports, column: :to_id end end Would only create one foreign key, on the column `from_id`. This commit allows multiple foreign keys to the same table to be created within one `create_table` block.
* Added numeric helper into migrations.Mehmet Emin İNAÇ2016-02-071-0/+2
| | | | | | | | | | | | | | | | | | With this addition, you can add a column into the table like: ``` create_table(:numeric_types) do |t| t.numeric :foo, precision: 10, scale: 2, default: 2.0 end ``` The result of the migration above is same with: ``` create_table(:numeric_types) do |t| t.decimal :foo, precision: 10, scale: 2, default: 2.0 end ```
* Pare back default `index` option for the migration generatorPrathamesh Sonpatki2016-01-241-1/+1
| | | | | | | | | | - Using `references` or `belongs_to` in migrations will always add index for the referenced column by default, without adding `index:true` option to generated migration file. - Users can opt out of this by passing `index: false`. - Legacy migrations won't be affected by this change. They will continue to run as they were before. - Fixes #18146
* Use a real migration version number in docsMatthew Draper2015-12-151-1/+1
| | | | | Even though this means more things to change when we bump after a release, it's more important that our examples are directly copyable.
* Use a deliberately-invalid migration version in all doc examplesMatthew Draper2015-12-151-1/+1
| | | | | | | | | | 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.
* Not passing `native_database_types` to `TableDefinition`Ryuta Kamizono2015-11-081-12/+3
| | | | | | The `native_database_types` only used in `TableDefinition` for look up the default `:limit` option. But this is duplicated process with `type_to_sql`. Passing `native_database_types` is not needed.
* Remove incorrect commentsAndrew White2015-11-041-4/+0
| | | | | | Columns are no longer stored in an attribute since b8a533d. [ci skip]
* Extract native getter to attr_reader.jbranchaud2015-10-211-5/+1
| | | | | The getter is doing nothing more than returning the ivar, so it can be extracted to an attr_reader.
* move documentation of column options to `add_column`. Closes #20400.Yves Senn2015-10-211-73/+6
| | | | | | | | | | | | [ci skip] It's been a source of confusion that the lower-level `add_column` referenced the higher level `column` method for available options. `column` supports additional functionality like `index: true` that is not present on `add_column`. This patch moves common option documentation to `add_column` and only documents the additional options in `column`.