aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
Commit message (Collapse)AuthorAgeFilesLines
...
* Reuse existing validate_index_length! methodPrathamesh Sonpatki2016-06-091-7/+7
| | | | - Followup of https://github.com/rails/rails/commit/1ea6cc11211dc89e3e14b2b641a3cca8a0a91d55.
* Respect options passed to `foreign_key` when reverting `add_reference`Sean Griffin2016-05-311-4/+9
| | | | | | | | | | | | The code incorrectly assumes that the option was written as `foreign_key: true`, but that is not always the case. This now mirrors the behavior of reverting `add_foreign_key`. The code was changed to use kwargs while I was touching it, as well. This could really use a refactoring to go through the same code paths as `add_refernce` in the future, so we don't duplicate default values. Fixes #25169
* Add Expression Indexes and Operator Classes support for PostgreSQLRyuta Kamizono2016-04-241-3/+17
| | | | | | | | | | | | | | | | Example: create_table :users do |t| t.string :name t.index 'lower(name) varchar_pattern_ops' end Fixes #19090. Fixes #21765. Fixes #21819. Fixes #24359. Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
* remove_index do not fetch indexes if name is specifiedSeva Orlov2016-04-241-1/+7
| | | | | | There is no need to fetch all table indexes in remove_index if name is specified. If name is wrong, then StatementInvalid will be raised. Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
* Add `:nodoc:` to `insert_versions_sql` [ci skip]Ryuta Kamizono2016-04-241-1/+1
| | | | Follow up to #24685. `insert_versions_sql` is not public API.
* Schema load: Fix dupe version insertJeremy Daer2016-04-221-1/+1
| | | | Re. 6e098284e97250eaed6f30f5c7c362d87da986b0
* https://github.com/rails/rails/commit/42dd2336b31a8d98776d039a2b9fd7f834156a ↵Vipul A M2016-04-231-4/+16
| | | | | | | | | 78 changed INSERT INTO versions to run in 1 single query. This breaks for sqlite versions < 3.7.11, which is especially the case on Ubuntu 12.04 LTS, that has SQLite version 3.7.9 as default. So we check for support for multi insert, before performing single query inserts, else fallback to older version of running multiple queries. [Vipul A M & Yasuo Honda]
* Revert "add doc for `:type` option of `#create_join_table` [ci skip]"प्रथमेश Sonpatki2016-04-211-2/+0
|
* add doc for `:type` option of `#create_join_table` [ci skip]yuuji.yaginuma2016-04-211-0/+2
| | | | Follow up to #24221.
* Merge pull request #24221 from gregmolnar/uuidKasper Timm Hansen2016-04-201-2/+3
|\ | | | | create_join_table should work with uuid
| * add column type option to create_join_table to support uuidGreg Molnar2016-03-171-2/+3
| |
* | Database comments: switch to keyword args for new table optionsJeremy Daer2016-04-181-15/+14
| | | | | | | | | | | | * Switch to keyword args where we can without breaking compat. * Use add_table_options! for :options, too. * Some code polish.
* | Merge pull request #22911 from Envek/database_commentsJeremy Daer2016-04-161-6/+30
|\ \ | | | | | | | | | Add support for specifying comments for tables, columns, and indexes in database itself
| * | Add support for specifying comments for tables, columns, and indexes.Andrey Novikov2016-04-161-6/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | | [ci skip] docs for add_references index optionAlex Handley2016-04-161-1/+10
|/ / | | | | | | | | | | - Add link for finding the addional options for index. - Add example for unique index as this is a common requirement. - Add link in guide for index options.
* / Fix description for method ↵Bogdan2016-03-271-2/+2
|/ | | | ActiveRecord::ConnectionAdapters::SchemaStatements#add_timestamps [ci skip]
* Fixed comments of add_foreign_key methodSalman Afzal Siddiqui2016-03-101-2/+2
| | | The comments of add_foreign_key method was displaying incorrect constraint name.
* Add numeric type in the doc [ci skip]Ryuta Kamizono2016-02-081-3/+3
| | | | Follow up to #23508.
* Merge pull request #23460 from ↵Sean Griffin2016-02-031-1/+1
|\ | | | | | | | | kamipo/innodb_supports_fulltext_and_spatial_indexes InnoDB supports FULLTEXT and Spatial Indexes [ci skip]
| * InnoDB supports FULLTEXT and Spatial Indexes [ci skip]Ryuta Kamizono2016-02-041-1/+1
| | | | | | | | | | https://dev.mysql.com/doc/refman/5.7/en/innodb-fulltext-index.html https://dev.mysql.com/doc/refman/5.7/en/creating-spatial-indexes.html
* | SQLite 2 support has been dropped [ci skip]Ryuta Kamizono2016-02-041-2/+0
|/
* Avoid extra `show variables` in migrationRyuta Kamizono2016-02-011-1/+5
| | | | | | | | | | | | | `initialize_schema_migrations_table` is called in every migrations. https://github.com/rails/rails/blob/v5.0.0.beta1/activerecord/lib/active_record/migration.rb#L1080 https://github.com/rails/rails/blob/v5.0.0.beta1/activerecord/lib/active_record/schema.rb#L51 This means that extra `show variables` is called regardless of the existence of `schema_migrations` table. This change is to avoid extra `show variables` if `schema_migrations` table exists.
* Merge pull request #23345 from ↵Rafael França2016-01-301-0/+6
|\ | | | | | | | | yui-knk/warning_when_composite_primary_key_is_detected Warn if `AR.primary_key` is called for a table who has composite prim…
| * Warn if `AR.primary_key` is called for a table who has composite primary keyyui-knk2016-01-301-0/+6
| | | | | | | | | | | | | | | | If `AR.primary_key` is called for a table who has composite primary key, the method returns `nil`. This behavior sometimes generates invalid SQL. The first time developers notice to invalid SQL is when they execute SQL. This commit enables developers to know they are doing something dangerous as soon as possible.
* | Merge pull request #23349 from kamipo/refactor_column_existsRafael França2016-01-301-7/+8
|\ \ | | | | | | Refactor `column_exists?` in `SchemaStatements`
| * | Refactor `column_exists?` in `SchemaStatements`Ryuta Kamizono2016-01-301-7/+8
| |/
* / Explicitly define `columns` method as an interfaceyui-knk2016-01-301-1/+3
|/ | | | | | `ActiveRecord::ConnectionAdapters::SchemaStatements#columns` is defined here as an interface method here. So changes to raise `NotImplementedError` same as `tables`, `views` ...etc.
* Fix a bug with initialize schema_migrations tableMikhail Grachev2016-01-281-1/+1
| | | | | | | This line causes an error when executing the command: `rails db:drop db:create db:schema:load` ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: syntax error at or near "{" LINE 1: ...NSERT INTO "schema_migrations" (version) VALUES (#{v}), (#{v...
* INSERT INTO schema_migrations in 1 SQLAkira Matsuda & Naoto Koshikawa2016-01-271-10/+8
| | | | | | | We found that inserting all 600 schema_migrations for our mid-sized app takes about a minute on a cloud based CI environment. I assume that the original code did not use multi-row-insert because SQLite3 was not supporting the syntax back then, but it's been supported since 3.7.11: http://www.sqlite.org/releaselog/3_7_11.html
* Merge pull request #22967 from schneems/schneems/generic-metadataSean Griffin2016-01-081-0/+4
|\ | | | | Prevent destructive action on production database
| * Prevent destructive action on production databaseschneems2016-01-071-0/+4
| | | | | | | | | | | | | | This PR introduces a key/value type store to Active Record that can be used for storing internal values. It is an alternative implementation to #21237 cc @sgrif @matthewd. It is possible to run your tests against your production database by accident right now. While infrequently, but as an anecdotal data point, Heroku receives a non-trivial number of requests for a database restore due to this happening. In these cases the loss can be large. To prevent against running tests against production we can store the "environment" version that was used when migrating the database in a new internal table. Before executing tests we can see if the database is a listed in `protected_environments` and abort. There is a manual escape valve to force this check from happening with environment variable `DISABLE_DATABASE_ENVIRONMENT_CHECK=1`.
* | Add `columns_for_distinct` for MySQL 5.7 with ONLY_FULL_GROUP_BYRyuta Kamizono2015-12-231-2/+3
| | | | | | | | | | | | | | | | | | In MySQL 5.7.5 and up, ONLY_FULL_GROUP_BY affects handling of queries that use DISTINCT and ORDER BY. It requires the ORDER BY columns in the select list for distinct queries, and requires that the ORDER BY include the distinct column. See https://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html
* | Support removing custom-names indexes when only specifying column namesGrey Baker2015-12-151-13/+27
| |
* | Ignore index name in `index_exists?` when not passed a name to check forGrey Baker2015-12-151-2/+1
|/
* Merge pull request #22214 from ↵Rafael França2015-11-241-1/+1
|\ | | | | | | | | kamipo/not_passing_native_database_types_to_table_definition Not passing `native_database_types` to `TableDefinition`
| * Not passing `native_database_types` to `TableDefinition`Ryuta Kamizono2015-11-081-1/+1
| | | | | | | | | | | | 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.
* | Deprecate `#table_exists?`, `#tables` and passing arguments to `#talbes`yui-knk2015-11-091-2/+2
|/ | | | | | | | | | Reported on #21509, how views is treated by `#tables` are differ by each adapters. To fix this different behavior, after Rails 5.0 is released, deprecate `#tables`. And `#table_exists?` would check both tables and views. To make their behavior consistent with `#tables`, after Rails 5.0 is released, deprecate `#table_exists?`.
* move documentation of column options to `add_column`. Closes #20400.Yves Senn2015-10-211-6/+75
| | | | | | | | | | | | [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`.
* applies new doc guidelines to Active Record.Yves Senn2015-10-141-10/+11
| | | | | | | | | | | | | | | | | | | The focus of this change is to make the API more accessible. References to method and classes should be linked to make it easy to navigate around. This patch makes exzessiv use of `rdoc-ref:` to provide more readable docs. This makes it possible to document `ActiveRecord::Base#save` even though the method is within a separate module `ActiveRecord::Persistence`. The goal here is to bring the API closer to the actual code that you would write. This commit only deals with Active Record. The other gems will be updated accordingly but in different commits. The pass through Active Record is not completely finished yet. A follow up commit will change the spots I haven't yet had the time to update. /cc @fxn
* `:to_table` when adding a fk through `add_reference`.Yves Senn2015-10-131-0/+4
| | | | | | | | | | | | Closes #21563. The `name` argument of `add_references` was both used to generate the column name `<name>_id` and as the target table for the foreign key `name.pluralize`. It's primary purpose is to define the column name. In cases where the `to_table` of the foreign key is different than the column name we should be able to specify it individually.
* Merge pull request #21005 from jaredbeck/patch-1Arthur Nogueira Neves2015-10-041-1/+3
|\ | | | | Docs: Update options for add_reference
| * Docs: Update options for add_referenceJared Beck2015-07-231-1/+3
| | | | | | [ci skip]
* | Fix proper fonts in `change_column_null` method docs. [ci skip]amitkumarsuroliya2015-09-271-2/+2
| |
* | introduce `conn.data_source_exists?` and `conn.data_sources`.Yves Senn2015-09-221-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | These new methods are used from the Active Record model layer to determine which relations are viable to back a model. These new methods allow us to change `conn.tables` in the future to only return tables and no views. Same for `conn.table_exists?`. The goal is to provide the following introspection methods on the connection: * `tables` * `table_exists?` * `views` * `view_exists?` * `data_sources` (views + tables) * `data_source_exists?` (views + tables)
* | Merge pull request #21693 from joshuapinter/patch-1Jeremy Daer2015-09-201-0/+2
|\ \ | | | | | | Add title for key lengths for multiple keys.
| * | Add title for key lengths for multiple keys.Joshua Pinter2015-09-201-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | Previously there was no separator between the two code examples so it looked like: ```ruby CREATE INDEX by_name ON accounts(name(10)) add_index(:accounts, [:name, :surname], name: 'by_name_surname', length: {name: 10, surname: 15}) ```
* | | Support for foreign keys in create tableRyuta Kamizono2015-09-201-13/+8
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If foreign keys specified in create table, generated SQL is slightly more efficient. Definition: ``` create_table :testings do |t| t.references :testing_parent, foreign_key: true end ``` Before: ``` CREATE TABLE "testings" ("id" serial primary key, "testing_parent_id" integer); ALTER TABLE "testings" ADD CONSTRAINT "fk_rails_a196c353b2" FOREIGN KEY ("testing_parent_id") REFERENCES "testing_parents" ("id"); ``` After: ``` CREATE TABLE "testings" ("id" serial primary key, "testing_parent_id" integer, CONSTRAINT "fk_rails_a196c353b2" FOREIGN KEY ("testing_parent_id") REFERENCES "testing_parents" ("id")); ```
* | Merge pull request #21609 from kamipo/do_not_dump_view_as_tableJeremy Daer2015-09-191-0/+13
|\ \ | | | | | | | | | Do not dump a view as a table in sqlite3, mysql and mysql2 adapters
| * | Add `#views` and `#view_exists?` methods on connection adaptersRyuta Kamizono2015-09-131-0/+13
| | |
* | | Merge pull request #21607 from kamipo/remove_unnecessary_display_widthJeremy Daer2015-09-191-3/+3
|\ \ \ | | | | | | | | Remove unnecessary display width