aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
Commit message (Collapse)AuthorAgeFilesLines
...
| | * | Make ActiveRecord frozen string literal friendly.Pat Allan2017-06-201-4/+4
| | | |
| * | | Don't cache queries for schema statementsRyuta Kamizono2017-06-301-10/+10
| | |/ | |/| | | | | | | | | | | | | `test_middleware_caches` is sometimes failed since #29454. The failure is due to schema statements are affected by query caching. Bypassing query caching for schema statements to avoid the issue.
* / | [Active Record] require => require_relativeAkira Matsuda2017-07-011-10/+10
|/ /
* | Use `quote` method rather than single quotes to identifiers in SQLRyuta Kamizono2017-06-291-1/+1
| | | | | | | | | | | | Because identifiers in SQL could include a single quote. Related #24950, #26784.
* | Use bulk INSERT to insert fixturesKir Shatrov2017-06-201-0/+17
|/ | | | | | | | Improves the performance from O(n) to O(1). Previously it would require 50 queries to insert 50 fixtures. Now it takes only one query. Disabled on sqlite which doesn't support multiple inserts.
* Consolidate database specific JSON types to `Type::Json`Ryuta Kamizono2017-05-301-3/+2
|
* Deserialize a raw value from the database in `changed_in_place?` for ↵Ryuta Kamizono2017-05-301-5/+0
| | | | | | | | `AbstractJson` Structured type values sometimes caused representation problems (keys sort order, spaces, etc). A raw value from the database should be deserialized (normalized) to prevent the problems.
* Add option for class_attribute default (#29270)David Heinemeier Hansson2017-05-291-2/+1
| | | | | | | | | | | | * Allow a default value to be declared for class_attribute * Convert to using class_attribute default rather than explicit setter * Removed instance_accessor option by mistake * False is a valid default value * Documentation
* Don't pass `arel.engine` to `Arel::SelectManager.new`Ryuta Kamizono2017-05-051-6/+4
| | | | | | The argument of `Arel::SelectManager.new` is `table`, not `engine`. https://github.com/rails/arel/blob/v8.0.0/lib/arel/select_manager.rb#L10
* Deprecate `supports_statement_cache?`Ryuta Kamizono2017-05-011-6/+0
| | | | | | | | | | | | | | `supports_statement_cache?` was introduced in 3.1.0.beta1 (104d0b2) for bind parameter substitution, but it is no longer used in 3.1.0.rc1 (73ff679). Originally it should respect `prepared_statements` rather than `supports_statement_cache?` (fd39847). One more thing, named `supports_statement_cache?` is pretty misreading. We have `StatementCache` and `StatementPool`. However, `supports_statement_cache?` doesn't mean `StatementCache`, but `StatementPool` unlike its name. https://github.com/rails/rails/blob/v5.1.0/activerecord/lib/active_record/statement_cache.rb https://github.com/rails/rails/blob/v5.1.0/activerecord/lib/active_record/connection_adapters/statement_pool.rb
* Don't fallback to utf8mb3 after MySQL 8.0.0Ryuta Kamizono2017-04-171-8/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `internal_string_options_for_primary_key` is used for creating internal tables in newly apps. But it is no longer needed after MySQL 8.0.0. MySQL 5.7 has introduced `innodb_default_row_format` (default `DYNAMIC`) and has deprecated `innodb_large_prefix` and `innodb_file_format`. The purpose of the deprecated options was for compatibility with earlier versions of InnoDB. https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html#sysvar_innodb_large_prefix > innodb_large_prefix is deprecated and will be removed in a future release. innodb_large_prefix was introduced in MySQL 5.5 to disable large index key prefixes for compatibility with earlier versions of InnoDB that do not support large index key prefixes. https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html#sysvar_innodb_file_format > The innodb_file_format option is deprecated and will be removed in a future release. The purpose of the innodb_file_format option was to allow users to downgrade to the built-in version of InnoDB in MySQL 5.1. Now that MySQL 5.1 has reached the end of its product lifecycle, downgrade support provided by this option is no longer necessary. The deprecated options has removed in MySQL 8.0.0. It is no longer needed to take care newly created internal tables as a legacy format after MySQL 8.0.0. Fixes #28730.
* Support Descending Indexes for MySQLRyuta Kamizono2017-04-161-3/+1
| | | | | | | MySQL 8.0.1 and higher supports descending indexes: `DESC` in an index definition is no longer ignored. See https://dev.mysql.com/doc/refman/8.0/en/descending-indexes.html.
* Refactor `indexes` things in connection adaptersRyuta Kamizono2017-04-161-33/+0
| | | | | | | * 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.
* Make internal methods to privateRyuta Kamizono2017-03-271-35/+2
|
* Merge pull request #28068 from kamipo/refactor_data_sourcesRafael França2017-03-131-67/+12
|\ | | | | Extract `data_source_sql` to refactor data source statements
| * Extract `data_source_sql` to refactor data source statementsRyuta Kamizono2017-02-201-67/+12
| |
* | Deprecate `supports_migrations?` on connection adaptersRyuta Kamizono2017-02-271-5/+0
| | | | | | | | | | | | | | `supports_migrations?` was added at 4160b518 to determine if schema statements (`create_table`, `drop_table`, etc) are implemented in the adapter. But all tested databases has been supported migrations since a4fc93c3 at least.
* | Merge pull request #28176 from kamipo/push_valid_type_up_to_abstract_adapterAndrew White2017-02-261-4/+0
|\ \ | | | | | | Push `valid_type?` up to abstract adapter
| * | Push `valid_type?` up to abstract adapterRyuta Kamizono2017-02-261-4/+0
| | | | | | | | | | | | | | | | | | | | | `valid_type?` should return true if a type exists in `native_database_types` at least. https://github.com/rails/rails/blob/v5.1.0.beta1/activerecord/lib/active_record/schema_dumper.rb#L136
* | | Fix `change_column` to drop default with `null: false`Ryuta Kamizono2017-02-261-2/+2
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently `change_column` cannot drop default if `null: false` is specified at the same time. This change fixes the issue. ```ruby # cannot drop default change_column "tests", "contributor", :boolean, default: nil, null: false # we need the following workaround currently change_column "tests", "contributor", :boolean, null: false change_column "tests", "contributor", :boolean, default: nil ``` Closes #26582
* | Fix `wait_timeout` to configurable for mysql2 adapterRyuta Kamizono2017-02-241-2/+2
| | | | | | | | Fixes #26556.
* | Correctly dump native timestamp types for MySQLRyuta Kamizono2017-02-231-1/+2
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The native timestamp type in MySQL is different from datetime type. Internal representation of the timestamp type is UNIX time, This means that timestamp columns are affected by time zone. ``` > SET time_zone = '+00:00'; Query OK, 0 rows affected (0.00 sec) > INSERT INTO time_with_zone(ts,dt) VALUES (NOW(),NOW()); Query OK, 1 row affected (0.02 sec) > SELECT * FROM time_with_zone; +---------------------+---------------------+ | ts | dt | +---------------------+---------------------+ | 2016-02-07 22:11:44 | 2016-02-07 22:11:44 | +---------------------+---------------------+ 1 row in set (0.00 sec) > SET time_zone = '-08:00'; Query OK, 0 rows affected (0.00 sec) > SELECT * FROM time_with_zone; +---------------------+---------------------+ | ts | dt | +---------------------+---------------------+ | 2016-02-07 14:11:44 | 2016-02-07 22:11:44 | +---------------------+---------------------+ 1 row in set (0.00 sec) ```
* Add `default_index_type?` to the generic schema dumper doesn't have the ↵Ryuta Kamizono2017-02-141-0/+4
| | | | knowledge about an index type
* Deprecate `supports_primary_key?`Ryuta Kamizono2017-02-121-4/+0
| | | | | | | | | | | | `supports_primary_key?` was added to determine if `primary_key` is implemented in the adapter in f060221. But we already use `primary_key` without `supports_primary_key?` (207f266, 5f3cf42) and using `supports_primary_key?` has been removed in #1318. This means that `supports_primary_key?` is no longer used in the internal and Active Record doesn't work without `primary_key` is implemented (all adapters must implement `primary_key`). Closes #27977
* Refactor `ColumnDefinition` to contain `options` hashRyuta Kamizono2017-02-091-2/+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.
* Merge pull request #26378 from ↵Jeremy Daer2017-02-061-2/+2
|\ | | | | | | | | kamipo/decouple_building_arel_ast_for_uniqueness_validator Decouple the building Arel ASTs for uniqueness validator
| * Add `:nodoc:` to `case_sensitive_comparison` and `case_insensitive_comparison`Ryuta Kamizono2017-01-201-1/+1
| | | | | | | | These methods are obviously for internal use.
| * Decouple the building Arel ASTs for uniqueness validatorRyuta Kamizono2016-12-251-1/+1
| | | | | | | | | | | | Currently uniqueness validator is coupled with building Arel ASTs. This commit extracts `WhereClauseFactory#build_for_case_sensitive` for decouple the building Arel ASTs.
* | Virtual/generated column support for MySQL 5.7.5+ and MariaDB 5.2.0+Ryuta Kamizono2017-02-011-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | Optimizing information_schema query for `foreign_keys`Ryuta Kamizono2017-01-051-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Need `table_name` to avoid all databases scan. See https://dev.mysql.com/doc/refman/5.7/en/information-schema-optimization.html. ``` > EXPLAIN SELECT fk.referenced_table_name AS 'to_table', fk.referenced_column_name AS 'primary_key', fk.column_name AS 'column', fk.constraint_name AS 'name', rc.update_rule AS 'on_update', rc.delete_rule AS 'on_delete' FROM information_schema.key_column_usage fk JOIN information_schema.referential_constraints rc USING (constraint_schema, constraint_name) WHERE fk.referenced_column_name IS NOT NULL AND fk.table_schema = 'activerecord_unittest' AND fk.table_name = 'fk_test_has_pk' AND rc.table_name = 'fk_test_has_pk'\G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: fk partitions: NULL type: ALL possible_keys: NULL key: TABLE_SCHEMA,TABLE_NAME key_len: NULL ref: NULL rows: NULL filtered: NULL Extra: Using where; Open_full_table; Scanned 0 databases *************************** 2. row *************************** id: 1 select_type: SIMPLE table: rc partitions: NULL type: ALL possible_keys: NULL key: TABLE_NAME key_len: NULL ref: NULL rows: NULL filtered: NULL Extra: Using where; Open_full_table; Scanned 1 database; Using join buffer (Block Nested Loop) 2 rows in set, 1 warning (0.00 sec) ``` Fixes #27579.
* | Deprecate passing `name` to `indexes` like `tables`Ryuta Kamizono2017-01-041-0/+6
| | | | | | | | | | Passing `name` to `tables` is already deprecated at #21601. Passing `name` to `indexes` is also unused.
* | Merge pull request #27435 from kamipo/follow_up_25307Sean Griffin2017-01-031-2/+2
|\ \ | | | | | | Active Record supports MySQL >= 5.1.10
| * | Active Record supports MySQL >= 5.1.10Ryuta Kamizono2016-12-221-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Follow up to #25307 and #23458. Related with #27422. We are using `information_schema.referential_constraints` since #25307. The table was introduced in MySQL 5.1.10. MySQL 5.0 is too old. It is enough to support >= 5.1.10 at least. MySQL 5.0 GA was released in Dec 2005 and already EOL in Dec 2011. MySQL 5.1 GA was released in Dec 2008 and already EOL in Dec 2013.
* | | Revert "Merge pull request #27528 from kamipo/extract_casted_booleans"Kasper Timm Hansen2017-01-011-6/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As pointed out by @matthewd this change makes ImmutableString aware of MysqlString's existence whereas previously MysqlString was only overriding public API. cc @kamipo This reverts commit e632c2fa4cb60072a778ce95c952a0fa95e5b074, reversing changes made to 334a7dcf107cd3ff1697163d331d289d6d65dcd7.
* | | Extract `casted_true`/`casted_false` for `Type::ImmutableString`Ryuta Kamizono2017-01-011-14/+6
| | | | | | | | | | | | | | | | | | The only difference between `Type::ImmutableString` and its subclasses is the representation of the casted booleans. Prefer extracting `casted_true`/`casted_false` and override these by subclasses.
* | | `#tables` and `#table_exists?` and returns only tables and not viewsRafael Mendonça França2016-12-291-23/+20
| | |
* | | Remove deprecated `name` argument from `#tables`Rafael Mendonça França2016-12-291-7/+1
| | |
* | | Merge pull request #27402 from yui-knk/executeRafael França2016-12-281-1/+1
|\ \ \ | | | | | | | | Use `#execute` instead of `@connection.query`
| * | | Use `#execute` instead of `@connection.query`yui-knk2016-12-191-1/+1
| |/ / | | | | | | | | | | | | `@connection.query` bypasses instrumenting "sql.active_record". This behavior preventing us from debugging SQLs which Rails generates.
* | / Fix Rubocop violations and fix documentation visibilityRafael Mendonça França2016-12-281-14/+14
| |/ |/| | | | | | | | | Some methods were added to public API in 5b14129d8d4ad302b4e11df6bd5c7891b75f393c and they should be not part of the public API.
* | Privatize unneededly protected methods in Active RecordAkira Matsuda2016-12-241-19/+17
|/
* Merge pull request #25227 from kamipo/numeric_value_out_of_rangeSean Griffin2016-12-101-0/+3
|\ | | | | Translate numeric value out of range to the specific exception
| * Translate numeric value out of range to the specific exceptionRyuta Kamizono2016-12-061-0/+3
| | | | | | | | Raise `ActiveRecord::RangeError` when values that executed are out of range.
* | Merge pull request #27278 from kamipo/should_be_sync_primary_key_definitionSean Griffin2016-12-081-1/+1
|\ \ | |/ |/| Should be sync the `primary_key` definition with actually created
| * Should be sync the `primary_key` definition with actually createdRyuta Kamizono2016-12-061-1/+1
| | | | | | | | | | | | | | | | Actually the `primary_key` definition is not used but the inconsistency is confusing. Actual definition is `bigint auto_increment PRIMARY KEY` so `UNSIGNED` and `(8)` is unnecessary. See also #21607.
* | Translate NOT NULL violation to the specific exceptionRyuta Kamizono2016-12-061-0/+4
| | | | | | | | | | Raise `ActiveRecord::NotNullViolation` when a record cannot be inserted or updated because it would violate a not null constraint.
* | Merge pull request #26687 from kamipo/fix_add_index_to_normalize_optionsMatthew Draper2016-12-061-0/+1
|\ \ | |/ |/| Fix `add_index` to normalize column names and options
| * Fix `add_index` to normalize column names and optionsRyuta Kamizono2016-10-031-0/+1
| | | | | | | | | | | | | | | | | | | | Currently does not work the following code. ```ruby add_index(:people, ["last_name", "first_name"], order: { last_name: :desc, first_name: :asc }) ``` Normalize column names and options to fix the issue.
* | Make pg adapter use bigserial for pk by defaultPavel Pravosud2016-12-051-1/+23
| |
* | Change MySQL and Postgresql to use Bigint primary keysJon McCartie2016-12-051-1/+1
| |