aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/schema_dumper.rb
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #25340 from kamipo/prevent_table_comment_queryRafael França2016-07-281-4/+4
|\ | | | | Prevent `table_comment` query if a table doesn't have a comment
| * Prevent `table_comment` query if a table doesn't have a commentRyuta Kamizono2016-06-101-4/+4
| |
* | Move the warning about composite primary key to `AttributeMethods::PrimaryKey`Ryuta Kamizono2016-07-021-6/+1
|/ | | | | | | | | | | Actually schema dumper/creation supports composite primary key (#21614). Therefore it should not show the warning about composite primary key in connection adapter. This change moves the warning to `AttributeMethods::PrimaryKey` and suppress the warning for habtm join table. Fixes #25388.
* Remove magic comment in generated `schema.rb`Ryuta Kamizono2016-05-121-4/+0
| | | | | Rails 5.0 has been dropped Ruby 1.9 support. I think no need magic comment anymore.
* Dump indexes in `create_table` for generates SQL in one queryRyuta Kamizono2016-04-201-20/+33
| | | | | If the adapter supports indexes in create table, it generates SQL in one query.
* Database comments: Treat blank comments as no comment. Don't dump blank ↵Jeremy Daer2016-04-191-1/+1
| | | | comments.
* Database comments: switch to keyword args for new table optionsJeremy Daer2016-04-181-2/+3
| | | | | | * 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/+4
| | | | | | | | | | | | | 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
* Merge pull request #24054 from kamipo/extract_default_primary_keyRafael França2016-03-111-1/+1
|\ | | | | Extract `default_primary_key?` to refactor `column_spec_for_primary_key`
| * Extract `default_primary_key?` to refactor `column_spec_for_primary_key`Ryuta Kamizono2016-03-111-1/+1
| |
* | Initialize `column.table_name` immediately for `column.serial?` correctly ↵Ryuta Kamizono2016-03-081-4/+1
|/ | | | | | | | working Currently the results of `column.serial?` is not correct. For `column.serial?` correctly working, initialize `column.table_name` immediately.
* Revert "Dump indexes in `create_table` instead of `add_index`"Sean Griffin2016-02-051-4/+6
| | | | | | | | | | This reverts commit 99801c6a7b69eb4b006a55de17ada78f3a0fa4c1. Ultimately it doesn't matter whether `add_index` or `t.index` are used in the schema dumper in any meaningful way. There are gems out there which hook into the old behavior for things like indexing materialized views. Since the reverted commit doesn't seem to add much benefit, there's no reason for us to break these gems.
* Prevent destructive action on production databaseschneems2016-01-071-1/+1
| | | | | | | 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`.
* introduce `conn.data_source_exists?` and `conn.data_sources`.Yves Senn2015-09-221-1/+1
| | | | | | | | | | | | | | | | | 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 #21609 from kamipo/do_not_dump_view_as_tableJeremy Daer2015-09-191-1/+1
|\ | | | | | | Do not dump a view as a table in sqlite3, mysql and mysql2 adapters
| * Do not dump a view as a table in sqlite3, mysql and mysql2 adaptersRyuta Kamizono2015-09-131-1/+1
| | | | | | | | | | | | Now in sqlite3, mysql and mysql2 adapters, SchemaDumper dump a view as a table. It is incorrect behavior. This change excludes a view in schema.rb.
* | Correctly dump composite primary keyRyuta Kamizono2015-09-201-6/+13
| | | | | | | | | | | | | | | | | | Example: create_table :barcodes, primary_key: ["region", "code"] do |t| t.string :region t.integer :code end
* | Don't hardcode table nameschneems2015-09-161-1/+1
|/ | | | | The schema_migrations table name is configurable. We should use this value when checking for ignored table names when dumping schema instead of a hardcoded value.
* Remove unused already requireRyuta Kamizono2015-05-191-1/+0
|
* Merge pull request #19994 from kamipo/dump_indexes_in_create_tableRafael Mendonça França2015-05-031-6/+4
|\ | | | | | | Dump indexes in `create_table` instead of `add_index`
| * Dump indexes in `create_table` instead of `add_index`Ryuta Kamizono2015-05-031-6/+4
| | | | | | | | | | If the adapter supports indexes in create table, generated SQL is slightly more efficient.
* | Correctly dump `:options` on `create_table` for MySQLRyuta Kamizono2015-05-031-0/+4
|/
* Add `:charset` and `:collation` options support for MySQL string and text ↵Ryuta Kamizono2015-03-061-1/+4
| | | | | | | | | | | columns Example: create_table :foos do |t| t.string :string_utf8_bin, charset: 'utf8', collation: 'utf8_bin' t.text :text_ascii, charset: 'ascii' end
* Improve a dump of the primary key support.Ryuta Kamizono2014-12-291-5/+6
| | | | If it is not a default primary key, correctly dump the type and options.
* Dump the default `nil` for PostgreSQL UUID primary key.Ryuta Kamizono2014-12-261-1/+1
|
* `force: :cascade` to recreate tables referenced by foreign-keys.Yves Senn2014-12-191-1/+1
|
* no need to pass native_database_types aroundYves Senn2014-12-021-2/+1
|
* Remove is_a? check when ignoring tablesSean Griffin2014-11-201-6/+1
| | | | | Technically changes the API, as it will allow any object which responds to `===`. Personally, I think this is more flexible.
* add bigserial pk supportAaron Patterson2014-10-291-0/+2
|
* do not dump foreign keys for ignored tables.Yves Senn2014-09-171-1/+1
|
* Schema dumper: all connection adapters implement #primary_key, so rely on it ↵Jeremy Kemper2014-09-071-10/+1
| | | | exclusively
* Fix warnings for undefined local variableTee Parham2014-09-071-6/+10
| | | | | * Add private method primary_key_for, which more clearly shows that the expected return value is nil when a primary key is not found.
* Prefer "if any?" to "unless empty?"Tee Parham2014-09-071-9/+6
| | | | | * Consistent whitespace * Remove unnecessary parentheses
* Convert string concatenations to substitutionsTee Parham2014-09-071-15/+15
|
* Extract iterator method in AR::SchemaDumperCaleb Thompson2014-07-251-10/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Gems which wish to tie into ActiveRecord::SchemaDumper need to duplicate this logic currently. [Foreigner] is one such example, as is a library I'm currently working on but which hasn't been released yet: def tables_with_foreign_keys(stream) tables_without_foreign_keys(stream) @connection.tables.sort.each do |table| next if ['schema_migrations', ignore_tables].flatten.any? do |ignored| case ignored when String; table == ignored when Regexp; table =~ ignored else raise StandardError, 'ActiveRecord::SchemaDumper.ignore_tables accepts an array of String and / or Regexp values.' end end foreign_keys(table, stream) end end [Foreigner]: https://github.com/matthuhiggins/foreigner/blob/master/lib/foreigner/schema_dumper.rb#L36-L43 Extract the skip logic to a method, making it much simpler to follow this same behavior in gems that are tying into the migration flow and let them dump only tables that aren't skipped without copying this block of code. The above code could then be simplified to: def tables_with_foreign_keys(stream) tables_without_foreign_keys(stream) @connection.tables.sort.each do |table| foreign_keys(table, stream) unless ignored?(table) end end It also, in my opinion, simplifies the logic on ActiveRecord's side, and clarifies the intent of the skip logic.
* Dump PostgreSQL primary key with custom function as a default.Andrey Novikov2014-07-111-1/+2
| | | | | | | | | | | For example, if use pgcrypto extension in PostgreSQL 9.4 beta 1, where uuid-ossp extension isn't available for moment of writing, and thus to use a gen_random_uuid() method as a primary key default. In this case schema dumper wasn't able to correctly reconstruct create_table statement and lost primary key constraint on schema load. Fixes #16111.
* fk: use random digest namesYves Senn2014-06-261-3/+13
| | | | | | 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: dump foreign keys at the bottom to make sure tables exist.Yves Senn2014-06-261-6/+9
|
* fk: support for on_updateYves Senn2014-06-261-0/+1
|
* fk: rename `dependent` to `on_delete`Yves Senn2014-06-261-1/+1
|
* fk: support dependent option (:delete, :nullify and :restrict).Yves Senn2014-06-261-0/+2
|
* fk: dump foreign keys to schema.rbYves Senn2014-06-261-0/+22
| | | | respect `table_name_prefix` and `table_name_suffix`.
* Push default_function to superclass to avoid method checkRafael Mendonça França2013-10-141-1/+1
|
* Dump the default function when the primary key is uuidRafael Mendonça França2013-10-141-0/+1
| | | | Fixes #12489
* Creating options for schema dumper.wangjohn2013-08-221-5/+16
| | | | | These options make it easier to change the config from ActiveRecord::Base to use something else inside of the SchemaDumper.
* Make SchemaDumper emit "id: :uuid" when appropriate. Fixes #10451.Brian Buchanan2013-05-031-1/+4
|
* Add support for FULLTEXT and SPATIAL indexes using the :type flag for MySQL.Ken Mazaika2013-03-271-0/+2
|
* Dump the 'using' options for a SQL index into the schema.Ken Mazaika2013-03-271-0/+2
|
* Created a layer of abstraction for the valid type checking in schema dumper. ↵Ranjay Krishna2013-03-251-1/+1
| | | | Now, connection handles the check for valid types so that each database can handle the changes individually.
* Revert "checking in the abstractions for valid type checking:"Jon Leighton2013-02-151-1/+1
| | | | | | | | | | | | | | | | This reverts commit c321b309a9a90bbfa0912832c11b3fef52e71840. Conflicts: activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb Reason: failing test 1) Error: test_valid_column(ActiveRecord::ConnectionAdapters::SQLite3AdapterTest): NoMethodError: undefined method `column' for test/cases/adapters/sqlite3/sqlite3_adapter_test.rb:29:in `test_valid_column'