aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters
Commit message (Collapse)AuthorAgeFilesLines
* No need to get the exception variableRafael Mendonça França2015-09-011-6/+4
|
* Merge pull request #21318 from yahonda/pr21108Rafael Mendonça França2015-09-012-3/+7
|\ | | | | Support MySQL 5.7.8 which enables show_compatibility_56=off
| * Support MySQL 5.7.8 which enables show_compatibility_56=offYasuo Honda2015-08-212-3/+7
| |
* | pg, `create_schema`, `drop_schema` and `rename_table` quote schema name.Yves Senn2015-08-282-3/+8
| | | | | | | | | | | | | | | | Closes #21418. Previously schema names were not quoted. This leads to issues when a schema names contains a ".". Methods in `schema_statements.rb` should quote user input.
* | pg docs, `connection.tables` does not use the `name` argument.Yves Senn2015-08-281-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | [ci skip] Currently the `#tables` method does not make use of the `name` argument and always returns all the tables in the schema search path. However the docs suggest different behavior. While we should porbably adjust the implementation to provide this behavior, let's make the docs right for now (also for `4-2-stable`) and then implement the behavior on `master`.
* | PostgreSQL, add `:if_exists` to `#drop_schema`.Yves Senn2015-08-281-2/+2
| |
* | JSON is still an adapter specific type.Sean Griffin2015-08-215-3/+15
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Several changes were made in #21110 which I am strongly opposed to. (this is what I get for going on vacation. :trollface:) No type should be introduced into the generic `ActiveRecord::Type` namespace, and *certainly* should not be registered into the registry unconstrained unless it is supported by *all* adapters (which basically means that it was specified in the ANSI SQL standard). I do not think `# :nodoc:` ing the type is sufficient, as it still makes the code of Rails itself very unclear as to what the role of that class is. While I would argue that this shouldn't even be a super class, and that MySql and PG's JSON types are only superficially duplicated (they might look the same but will change for different reasons in the future). However, I don't feel strongly enough about it as a point of contention (and the biggest cost of harming the blameability has already occured), so I simply moved the superclass into a namespace where its role is absolutely clear. After this change, `attribute :foo, :json` will once again work with MySQL and PG, but not with Sqlite3 or any third party adapters. Unresolved questions -------------------- The types that and adapter publishes (at least those are unique to that adapter, and not adding additional behavior like `MysqlString` should probably be part of the adapter's public API. Should we standardize the namespace for these, and document them?
* Merge pull request #21282 from sjain1107/added_docsYves Senn2015-08-191-0/+3
|\ | | | | | | Added docs for TableDefinition #coloumns & #remove_column [ci skip]
| * Added docs for TableDefinition #coloumns & #remove_column [ci skip]sjain11072015-08-181-0/+3
| |
* | Add a native JSON data type support in MySQLRyuta Kamizono2015-08-187-50/+43
|/ | | | | | | | | | As of MySQL 5.7.8, MySQL supports a native JSON data type. Example: create_table :json_data_type do |t| t.json :settings end
* descriptive error message when fixtures contian a missing column.Yves Senn2015-08-131-2/+6
| | | | Closes #21201.
* Merge pull request #20459Sean Griffin2015-08-061-0/+24
|\
| * Add missing data types for ActiveRecord migrationsMehmet Emin İNAÇ2015-06-081-0/+24
| |
* | Should use `server_info[:version]` instead of `info[:version]`Ryuta Kamizono2015-08-041-1/+1
| | | | | | | | | | Because `info[:version]` is a client version, the server version is `server_info[:version]`.
* | Fixes documentation typo.Дмитро Будник2015-07-231-2/+2
| | | | | | Documentation had extra colon after keyword.
* | Ensure that microsecond precision is only used for version of mysql that ↵Jori Hardman2015-07-203-17/+25
| | | | | | | | support it. Fixes #19711
* | Freeze string literals when not mutated.schneems2015-07-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I wrote a utility that helps find areas where you could optimize your program using a frozen string instead of a string literal, it's called [let_it_go](https://github.com/schneems/let_it_go). After going through the output and adding `.freeze` I was able to eliminate the creation of 1,114 string objects on EVERY request to [codetriage](codetriage.com). How does this impact execution? To look at memory: ```ruby require 'get_process_mem' mem = GetProcessMem.new GC.start GC.disable 1_114.times { " " } before = mem.mb after = mem.mb GC.enable puts "Diff: #{after - before} mb" ``` Creating 1,114 string objects results in `Diff: 0.03125 mb` of RAM allocated on every request. Or 1mb every 32 requests. To look at raw speed: ```ruby require 'benchmark/ips' number_of_objects_reduced = 1_114 Benchmark.ips do |x| x.report("freeze") { number_of_objects_reduced.times { " ".freeze } } x.report("no-freeze") { number_of_objects_reduced.times { " " } } end ``` We get the results ``` Calculating ------------------------------------- freeze 1.428k i/100ms no-freeze 609.000 i/100ms ------------------------------------------------- freeze 14.363k (± 8.5%) i/s - 71.400k no-freeze 6.084k (± 8.1%) i/s - 30.450k ``` Now we can do some maths: ```ruby ips = 6_226k # iterations / 1 second call_time_before = 1.0 / ips # seconds per iteration ips = 15_254 # iterations / 1 second call_time_after = 1.0 / ips # seconds per iteration diff = call_time_before - call_time_after number_of_objects_reduced * diff * 100 # => 0.4530373333993266 miliseconds saved per request ``` So we're shaving off 1 second of execution time for every 220 requests. Is this going to be an insane speed boost to any Rails app: nope. Should we merge it: yep. p.s. If you know of a method call that doesn't modify a string input such as [String#gsub](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37) please [give me a pull request to the appropriate file](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37), or open an issue in LetItGo so we can track and freeze more strings. Keep those strings Frozen ![](https://www.dropbox.com/s/z4dj9fdsv213r4v/let-it-go.gif?dl=1)
* | Revert "Revert "Reduce allocations when running AR callbacks.""Guo Xiang Tan2015-07-161-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit bdc1d329d4eea823d07cf010064bd19c07099ff3. Before: Calculating ------------------------------------- 22.000 i/100ms ------------------------------------------------- 229.700 (± 0.4%) i/s - 1.166k Total Allocated Object: 9939 After: Calculating ------------------------------------- 24.000 i/100ms ------------------------------------------------- 246.443 (± 0.8%) i/s - 1.248k Total Allocated Object: 7939 ``` begin require 'bundler/inline' rescue LoadError => e $stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler' raise e end gemfile(true) do source 'https://rubygems.org' # gem 'rails', github: 'rails/rails', ref: 'bdc1d329d4eea823d07cf010064bd19c07099ff3' gem 'rails', github: 'rails/rails', ref: 'd2876141d08341ec67cf6a11a073d1acfb920de7' gem 'arel', github: 'rails/arel' gem 'sqlite3' gem 'benchmark-ips' end require 'active_record' require 'benchmark/ips' ActiveRecord::Base.establish_connection('sqlite3::memory:') ActiveRecord::Migration.verbose = false ActiveRecord::Schema.define do create_table :users, force: true do |t| t.string :name, :email t.boolean :admin t.timestamps null: false end end class User < ActiveRecord::Base default_scope { where(admin: true) } end admin = true 1000.times do attributes = { name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", email: "foobar@email.com", admin: admin } User.create!(attributes) admin = !admin end GC.disable Benchmark.ips(5, 3) do |x| x.report { User.all.to_a } end key = if RUBY_VERSION < '2.2' :total_allocated_object else :total_allocated_objects end before = GC.stat[key] User.all.to_a after = GC.stat[key] puts "Total Allocated Object: #{after - before}" ```
* | Merge pull request #20699 from ↵Rafael Mendonça França2015-06-271-1/+4
|\ \ | | | | | | | | | | | | vngrs/foreign_key_with_table_name_suffix_and_prefix Add table name prefix and suffix support for foreign keys
| * | Add table name prefix and suffix support to add_foreign_key and ↵Mehmet Emin İNAÇ2015-06-251-1/+4
| | | | | | | | | | | | | | | | | | remove_foreign_key methods fix tests
* | | Add reversible syntax for change_column_defaultPrem Sichanugrist2015-06-265-6/+24
|/ / | | | | | | | | | | | | | | | | | | | | | | | | Passing `:from` and `:to` to `change_column_default` makes this command reversible as user has defined its previous state. So, instead of having the migration command as: change_column_default(:posts, :state, "draft") They can write it as: change_column_default(:posts, :state, from: nil, to: "draft")
* | make `remove_index :table, :column` reversible.Yves Senn2015-06-151-1/+1
| | | | | | | | | | | | | | | | | | This used to raise a `IrreversibleMigration` error (since #10437). However since `remove_index :table, :column` is probably the most basic use-case we should make it reversible again. Conflicts: activerecord/CHANGELOG.md
* | Merge pull request #20226 from EpicH0liday/reversible-remove-foreign-keyYves Senn2015-06-121-1/+5
|\ \ | | | | | | | | | | | | | | | | | | Make remove_foreign_key reversible Conflicts: activerecord/CHANGELOG.md
| * | Add an invert method for remove_foreign_keyAster Ryan2015-06-111-1/+6
|/ /
* / Correctly handle array columns with defaults in the schema dumperSean Griffin2015-06-111-0/+5
|/ | | | | | | | | If the subtype provides custom schema dumping behavior, we need to defer to it. We purposely choose not to handle any values other than an array (which technically should only ever be `nil`, but I'd rather code defensively here). Fixes #20515.
* Merge pull request #20448 from sgrif/sg-postgresql-point-typeSean Griffin2015-06-073-0/+53
|\ | | | | Return a `Point` object from the PG Point type
| * Return a `Point` object from the PG Point typeSean Griffin2015-06-053-0/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This introduces a deprecation cycle to change the behavior of the default point type in the PostgreSQL adapter. The old behavior will continue to be available for the immediate future as `:legacy_point`. The current behavior of returning an `Array` causes several problems, the most significant of which is that we cannot differentiate between an array of points, and a point itself in the case of a column with the `point[]` type. The attributes API gives us a reasonable way to have a proper deprecation cycle for this change, so let's take advantage of it. If we like this change, we can also add proper support for the other geometric types (line, lseg, box, path, polygon, and circle), all of which are just aliases for string today. Fixes #20441
* | A few documentation tweaks [ci skip]Robin Dupret2015-06-071-1/+1
|/ | | | [Robin Dupret & Shunsuke Aida]
* Fixed typos in guidemanish-shrivastava2015-06-011-1/+1
|
* Add collation support for string and text columns in SQLite3Akshay Vishnoi2015-05-282-4/+66
|
* If specify `strict: :default` explicitly, do not set sql_mode.Ryuta Kamizono2015-05-261-2/+4
| | | | Related with #17370.
* Updated postgresql documentation link to use latest version [ci skip]Ronak Jangir2015-05-202-5/+5
|
* Remove unused already requireRyuta Kamizono2015-05-192-7/+0
|
* Remove `require 'arel/visitors/bind_visitor'`Ryuta Kamizono2015-05-193-4/+0
| | | | | This line introduced by the commit fd398475 for using `Arel::Visitors::BindVisitor`. Currently it is not used.
* Merge pull request #20212 from kamipo/avoid_heredocRafael Mendonça França2015-05-191-20/+5
|\ | | | | Avoid the heredoc in one line queries and simple queries
| * Avoid the heredoc in one line queries and simple queriesRyuta Kamizono2015-05-191-20/+5
| | | | | | | | Related with #20028.
* | Eliminate the duplication code of `StatementPool`Ryuta Kamizono2015-05-194-92/+36
|/
* Merge pull request #20175 from eugeneius/copy_schema_cache_after_forkRafael Mendonça França2015-05-181-1/+3
|\ | | | | Add schema cache to new connection pool after fork
| * Add schema cache to new connection pool after forkEugene Kenny2015-05-171-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Active Record detects when the process has forked and automatically creates a new connection pool to avoid sharing file descriptors. If the existing connection pool had a schema cache associated with it, the new pool should copy it to avoid unnecessarily querying the database for its schema. The code to detect that the process has forked is in ConnectionHandler, but the existing test for it was in the ConnectionManagement test file. I moved it to the right place while I was writing the new test for this change.
* | Merge pull request #20192 from kamipo/divide_to_column_options_handling_methodsRafael Mendonça França2015-05-182-10/+34
|\ \ | | | | | | Divide methods for handling column options separately
| * | Divide methods for handling column options separatelyRyuta Kamizono2015-05-182-10/+34
| |/
* | Merge pull request #20190 from kamipo/fix_serial_with_quoted_sequence_nameRafael Mendonça França2015-05-181-1/+2
|\ \ | | | | | | Fix `serial?` with quoted sequence name
| * | Fix `serial?` with quoted sequence nameRyuta Kamizono2015-05-181-1/+2
| |/
* / better `add_reference` documentation. [ci skip]Yves Senn2015-05-182-20/+18
|/ | | | | | | | | This patch - reduces the duplication among the `reference`-family methods. - better explains all the optians available for `add_reference`. - redirects to user from `references` to `add_reference`. Originated by #20184.
* Merge pull request #14938 from thedarkone/pool-lock-fixMatthew Draper2015-05-162-85/+406
|\ | | | | Reducing AR::ConPool's critical (synchronized) section
| * AR::ConPool - remove synchronization around connection cache.thedarkone2015-05-141-79/+303
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Renamed `@reserved_connections` -> `@thread_cached_conns`. New name clearly conveys the purpose of the cache, which is to speed-up `#connection` method. The new `@thread_cached_conns` now also uses `Thread` objects as keys (instead of previously `Thread.current.object_id`). Since there is no longer any synchronization around `@thread_cached_conns`, `disconnect!` and `clear_reloadable_connections!` methods now pre-emptively obtain ownership (via `checkout`) of all existing connections, before modifying internal data structures. A private method `release` has been renamed `thread_conn_uncache` to clear-up its purpose. Fixed some brittle `thread.status == "sleep"` tests (threads can go into sleep even without locks).
| * AR::ConPool - establish connections outside of critical section.thedarkone2015-05-141-27/+101
| |
| * AR::ConPool - reduce post checkout critical section.thedarkone2015-05-142-13/+35
| | | | | | | | Move post checkout connection verification out of mutex.synchronize.
* | Remove redundant require 'set' linesMehmet Emin İNAÇ2015-05-152-2/+0
|/
* :nodoc: postgresql add_columnTony Miller2015-05-131-3/+1
|