| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Follow up to #26735.
If `table_options` returns `{ comment: nil }`, `create_table` line is
broken.
Example:
```ruby
create_table "accounts", force: :cascade, do |t|
```
|
|
|
|
| |
`migration_keys` includes `name` but `name` is not a column option.
|
|
|
|
|
|
|
|
|
|
| |
```ruby
# Before
t.index ["firm_id", "type", "rating"], name: "company_index", order: {"rating"=>:desc}, using: :btree
# After
t.index ["firm_id", "type", "rating"], name: "company_index", order: { rating: :desc }, using: :btree
```
|
|
|
|
|
| |
Currently blank comment does not dump to `db/schema.rb`. But created it
even if specified blank.
|
|
|
|
|
| |
`format_string` is used for standardized column types/arguments spaces.
Now the standardization was removed at df84e9867219e9311aef6f4efd5dd9ec675bee5c.
|
|
|
|
|
| |
Now the schema dumper by default doesn't align the types and arguments
in the ruby format anymore.
|
| |
|
|
|
|
|
|
|
|
| |
Style/SpaceBeforeBlockBraces
Style/SpaceInsideBlockBraces
Style/SpaceInsideHashLiteralBraces
Fix all violations in the repository.
|
|
|
|
|
| |
The current code base is not uniform. After some discussion,
we have chosen to go with double quotes by default.
|
|\
| |
| | |
Prevent `table_comment` query if a table doesn't have a comment
|
| | |
|
|/
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
| |
Rails 5.0 has been dropped Ruby 1.9 support.
I think no need magic comment anymore.
|
|
|
|
|
| |
If the adapter supports indexes in create table, it generates SQL
in one query.
|
|
|
|
| |
comments.
|
|
|
|
|
|
| |
* Switch to keyword args where we can without breaking compat.
* Use add_table_options! for :options, too.
* Some code polish.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|\
| |
| | |
Extract `default_primary_key?` to refactor `column_spec_for_primary_key`
|
| | |
|
|/
|
|
|
|
|
|
| |
working
Currently the results of `column.serial?` is not correct. For
`column.serial?` correctly working, initialize `column.table_name`
immediately.
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
| |
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`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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)
|
|\
| |
| |
| | |
Do not dump a view as a table in sqlite3, mysql and mysql2 adapters
|
| |
| |
| |
| |
| |
| | |
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.
|
| |
| |
| |
| |
| |
| |
| |
| |
| | |
Example:
create_table :barcodes, primary_key: ["region", "code"] do |t|
t.string :region
t.integer :code
end
|
|/
|
|
|
| |
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.
|
| |
|
|\
| |
| |
| | |
Dump indexes in `create_table` instead of `add_index`
|
| |
| |
| |
| |
| | |
If the adapter supports indexes in create table, generated SQL is
slightly more efficient.
|
|/ |
|
|
|
|
|
|
|
|
|
|
|
| |
columns
Example:
create_table :foos do |t|
t.string :string_utf8_bin, charset: 'utf8', collation: 'utf8_bin'
t.text :text_ascii, charset: 'ascii'
end
|
|
|
|
| |
If it is not a default primary key, correctly dump the type and options.
|
| |
|
| |
|
| |
|
|
|
|
|
| |
Technically changes the API, as it will allow any object which responds
to `===`. Personally, I think this is more flexible.
|
| |
|
| |
|
|
|
|
| |
exclusively
|
|
|
|
|
| |
* Add private method primary_key_for, which more clearly shows that the
expected return value is nil when a primary key is not found.
|
|
|
|
|
| |
* Consistent whitespace
* Remove unnecessary parentheses
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
| |
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.
|
| |
|
| |
|