aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/schema_creation.rb
Commit message (Collapse)AuthorAgeFilesLines
* SQLite3: Implement `add_foreign_key` and `remove_foreign_key`Ryuta Kamizono2019-02-111-2/+2
| | | | | | | | | | | | 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-0/+3
|
* Add support for UNLOGGED Postgresql tablesJacob Evelyn2018-11-131-1/+6
| | | | | | | | | | | This commit adds support for the `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables` setting, which turns `CREATE TABLE` SQL statements into `CREATE UNLOGGED TABLE` statements. This can improve PostgreSQL performance but at the cost of data durability, and thus it is highly recommended that you *DO NOT* enable this in a production environment.
* Add an :if_not_exists option to create_tablefatkodima2018-11-081-1/+3
| | | | [fatkodima & Stefan Kanev]
* Enable `Performance/UnfreezeString` copyuuji.yaginuma2018-09-231-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`. ```ruby # frozen_string_literal: true require "bundler/inline" gemfile(true) do source "https://rubygems.org" gem "benchmark-ips" end Benchmark.ips do |x| x.report('+@') { +"" } x.report('dup') { "".dup } x.compare! end ``` ``` $ ruby -v benchmark.rb ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] Warming up -------------------------------------- +@ 282.289k i/100ms dup 187.638k i/100ms Calculating ------------------------------------- +@ 6.775M (± 3.6%) i/s - 33.875M in 5.006253s dup 3.320M (± 2.2%) i/s - 16.700M in 5.032125s Comparison: +@: 6775299.3 i/s dup: 3320400.7 i/s - 2.04x slower ```
* Use `delegate private: true` for `SchemaCreation`Ryuta Kamizono2018-03-021-3/+2
| | | | Duplicated method name list is no longer needed.
* Fix frozen string concatenation by indicating that it's mutableJeremy Daer2018-02-161-1/+1
| | | | References 89bcca59e91fa9da941de890012872e8288e77b0
* Remove usage of strip_heredoc in the framework in favor of <<~Rafael Mendonça França2018-02-161-4/+2
| | | | | 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.
* Remove passing needless empty string `options` in `create_table`Ryuta Kamizono2017-12-201-0/+1
| | | | Follow up of #31177.
* Should quote composite primary key namesRyuta Kamizono2017-09-041-1/+1
| | | | | | | Otherwise using reserved words as composite primary key names will be failed as an invalid SQL. Fixes #30518.
* 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.
* 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
| |
* | Make ActiveRecord frozen string literal friendly.Pat Allan2017-06-201-4/+4
|/
* Fix `create_table` with query from relationRyuta Kamizono2017-06-131-1/+6
| | | | | If a relation has binds, `connection.to_sql(relation)` without binds will generate invalid SQL. It should use `relation.to_sql` in that case.
* Make internal methods to privateRyuta Kamizono2017-03-271-0/+1
|
* Refactor `ColumnDefinition` to contain `options` hashRyuta Kamizono2017-02-091-13/+2
| | | | | | 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.
* Virtual/generated column support for MySQL 5.7.5+ and MariaDB 5.2.0+Ryuta Kamizono2017-02-011-0/+1
| | | | | | | | | | | | | | | | | | | 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
* SQLite: Foreign Key SupportRyuta Kamizono2017-01-171-3/+3
| | | | https://www.sqlite.org/foreignkeys.html
* applies new string literal convention in activerecord/libXavier Noria2016-08-061-4/+4
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Database comments: switch to keyword args for new table optionsJeremy Daer2016-04-181-7/+9
| | | | | | * 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-0/+12
| | | | | | | | | | | | | 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
* Support for foreign keys in create tableRyuta Kamizono2015-09-201-4/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | 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 #21589 from ↵Jeremy Daer2015-09-191-2/+6
|\ | | | | | | | | | | kamipo/eliminate_duplicated_visit_table_definition Eliminate the duplication code of `visit_TableDefinition`
| * Eliminate the duplication code of `visit_TableDefinition`Ryuta Kamizono2015-09-161-5/+13
| |
* | Merge pull request #21608 from ↵Jeremy Daer2015-09-191-6/+4
|\ \ | | | | | | | | | | | | kamipo/eliminate_duplicated_options_include_default_method Eliminate the duplicated `options_include_default?` method
| * | Eliminate the duplicated `options_include_default?` methodRyuta Kamizono2015-09-131-6/+4
| |/ | | | | | | Follow up 7ba2cd06.
* / Correctly dump composite primary keyRyuta Kamizono2015-09-201-3/+10
|/ | | | | | | | | Example: create_table :barcodes, primary_key: ["region", "code"] do |t| t.string :region t.integer :code end
* Merge pull request #19978 from kamipo/collation_option_support_for_postgresqlRafael Mendonça França2015-05-031-0/+1
|\ | | | | PostgreSQL: `:collation` support for string and text columns
| * Move the collation handling code from the MySQL adapter to common classesRyuta Kamizono2015-05-041-0/+1
| | | | | | | | | | Some databases like MySQL allow defining collation charset for specific columns.
* | Change the `visit_AddColumn` visiblity for the internal APIRyuta Kamizono2015-05-031-5/+5
|/
* Use `delegate` to call the methods to `@conn`Ryuta Kamizono2015-02-191-16/+3
|
* Refactor `quote_default_expression`Ryuta Kamizono2015-02-111-6/+1
| | | | | | | `quote_default_expression` and `quote_default_value` are almost the same handling for do not quote default function of `:uuid` columns. Rename `quote_default_value` to `quote_default_expression`, and remove duplicate code.
* An array type is a part of `sql_type`Ryuta Kamizono2015-02-081-1/+1
| | | | | | `sql_type` is reused in `lookup_cast_type`. If making it a part of `sql_type` when handled array option first, it isn't necessary to do again.
* `sql_type` has been determined already when quoting defaultsRyuta Kamizono2015-01-041-4/+2
| | | | No need to call `type_to_sql` again.
* Stop passing the column to the connection adapter when quoting defaultsSean Griffin2015-01-011-2/+2
| | | | | The column is no longer used for anything besides type casting, which is what we're trying to remove from the column entirely.
* Add bigint primary key support for MySQL.Ryuta Kamizono2014-12-281-0/+1
| | | | | | | Example: create_table :foos, id: :bigint do |t| end
* Support for any type primary key.Ryuta Kamizono2014-12-281-1/+5
|
* Merge pull request #17799 from kamipo/refactor_add_column_optionsRafael Mendonça França2014-11-281-2/+2
|\ | | | | Refactor `add_column_options!`, to move the quoting of default value for :uuid in `quote_value`.
| * Rename to `quote_default_expression` from `quote_value`Ryuta Kamizono2014-11-281-2/+2
| |
* | Refactor `SchemaCreation#visit_AddColumn`Ryuta Kamizono2014-11-271-3/+1
|/
* Add and Remove string/strip requireArthur Neves2014-09-021-0/+2
| | | | | | | Method .strip_heredoc is defined in active_support/core_ext/string/strip.rb so we need to require it. [fixes #16677]
* Always pass a column with a type object to quoteSean Griffin2014-06-281-0/+5
| | | | | | | | The only case where we got a column that was not `nil`, but did not respond to `cast_type` was when type casting the default value during schema creation. We can look up the cast type, and add that object to the column definition. Will allow us to consistently rely on the type objects for type casting in all directions.
* fk: review corrections: indent, visibility, syntax, wording.Yves Senn2014-06-261-18/+18
|
* fk: use random digest namesYves Senn2014-06-261-1/+1
| | | | | | The name of the foreign key is not relevant from a users perspective. Using random names resolves the urge to rename the foreign key when the respective table or column is renamed.
* fk: raise for invalid :on_update / :on_delete valuesYves Senn2014-06-261-3/+8
|
* fk: support for on_updateYves Senn2014-06-261-2/+3
|
* fk: rename `dependent` to `on_delete`Yves Senn2014-06-261-6/+5
|
* fk: support dependent option (:delete, :nullify and :restrict).Yves Senn2014-06-261-1/+12
|