1. 24 5月, 2020 1 次提交
    • R
      Default engine `ENGINE=InnoDB` is no longer dumped to make schema more agnostic · 3c6be5e5
      Ryuta Kamizono 提交于
      5 years ago, I made dumping full table options at #17569, especially to
      dump `ENGINE=InnoDB ROW_FORMAT=DYNAMIC` to use utf8mb4 with large key
      prefix.
      
      In that time, omitting the default engine `ENGINE=InnoDB` was not useful
      since `ROW_FORMAT=DYNAMIC` always remains as long as using utf8mb4 with
      large key prefix.
      
      But now, MySQL 5.7.9 has finally changed the default row format to
      DYNAMIC, utf8mb4 with large key prefix can be used without dumping the
      default engine and the row format explicitly.
      
      So now is a good time to make the default engine is omitted.
      
      Before:
      
      ```ruby
      create_table "accounts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", force: :cascade do |t|
      end
      ```
      
      After:
      
      ```ruby
      create_table "accounts", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
      end
      ```
      
      To entirely omit `:options` option to make schema agnostic, I've added
      `:charset` and `:collation` table options to exclude `CHARSET` and
      `COLLATE` from `:options`.
      
      Fixes #26209.
      Closes #29472.
      
      See also #33608, #33853, and #34742.
      3c6be5e5
  2. 10 5月, 2020 1 次提交
  3. 15 9月, 2019 1 次提交
  4. 13 9月, 2019 1 次提交
    • E
      Stop autoloading AbstractAdapter prematurely · b744372f
      Eugene Kenny 提交于
      In 7254d237, an autoload for
      `ConnectionAdapters::AbstractAdapter` was added to `active_record.rb`.
      
      Later in d6b923ad, a manual require for
      that class was added to `active_record/base.rb` as some constants under
      `ConnectionAdapters` weren't defined until `AbstractAdapter` was loaded.
      
      In 1efd8828, the require was removed and
      replaced with an autoload in `active_record.rb`, above the previous one.
      
      Because the first autoload was for the `ConnectionAdapters` constant and
      the second one tried to create it, the autoload would fire immediately.
      Rather than fixing the autoload problem, the require had effectively
      just been moved from `active_record/base.rb` to `active_record.rb`.
      
      Instead of defining autoloads for constants under `ConnectionAdapters`
      in the `abstract_adapter.rb` file, we can create a separate, autoloaded
      `connection_adapters.rb` file for this purpose.
      
      To avoid a "circular require considered harmful" warning from Ruby, we
      have to fix the module nesting in `schema_creation.rb`, as a followup to
      e4108fc6.
      
      `AbstractAdapter` loads many other dependencies, so making it autoload
      properly has a noticeable impact on the load time of `active_record.rb`.
      
      Benchmark:
      
          $ cat test.rb
          require "bundler/setup"
          before = ObjectSpace.each_object(Module).count
          start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
          require "active_record"
          finish = Process.clock_gettime(Process::CLOCK_MONOTONIC)
          after = ObjectSpace.each_object(Module).count
          puts "took #{finish - start} and created #{after - before} modules"
      
      Before:
      
          $ ruby test.rb
          took 0.47532399999909103 and created 901 modules
      
      After:
      
          $ ruby test.rb
          took 0.3299509999342263 and created 608 modules
      b744372f
  5. 13 6月, 2019 1 次提交
  6. 11 2月, 2019 2 次提交
  7. 13 11月, 2018 1 次提交
    • J
      Add support for UNLOGGED Postgresql tables · bfc4d8be
      Jacob Evelyn 提交于
      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.
      bfc4d8be
  8. 08 11月, 2018 1 次提交
  9. 23 9月, 2018 1 次提交
    • Y
      Enable `Performance/UnfreezeString` cop · 1b86d901
      yuuji.yaginuma 提交于
      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
      
      ```
      1b86d901
  10. 02 3月, 2018 1 次提交
  11. 17 2月, 2018 2 次提交
  12. 20 12月, 2017 1 次提交
  13. 04 9月, 2017 1 次提交
  14. 20 7月, 2017 1 次提交
  15. 02 7月, 2017 1 次提交
  16. 01 7月, 2017 1 次提交
  17. 20 6月, 2017 1 次提交
  18. 13 6月, 2017 1 次提交
  19. 26 3月, 2017 1 次提交
  20. 09 2月, 2017 1 次提交
  21. 02 2月, 2017 1 次提交
  22. 17 1月, 2017 1 次提交
  23. 07 8月, 2016 1 次提交
  24. 19 4月, 2016 1 次提交
  25. 16 4月, 2016 1 次提交
  26. 20 9月, 2015 2 次提交
    • R
      Support for foreign keys in create table · fdf371ab
      Ryuta Kamizono 提交于
      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"));
          ```
      fdf371ab
    • R
      Correctly dump composite primary key · ab128599
      Ryuta Kamizono 提交于
      Example:
      
          create_table :barcodes, primary_key: ["region", "code"] do |t|
            t.string :region
            t.integer :code
          end
      ab128599
  27. 16 9月, 2015 1 次提交
  28. 13 9月, 2015 1 次提交
  29. 04 5月, 2015 1 次提交
  30. 03 5月, 2015 1 次提交
  31. 19 2月, 2015 1 次提交
  32. 11 2月, 2015 1 次提交
    • R
      Refactor `quote_default_expression` · bb2a7c38
      Ryuta Kamizono 提交于
      `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.
      bb2a7c38
  33. 08 2月, 2015 1 次提交
  34. 04 1月, 2015 1 次提交
  35. 02 1月, 2015 1 次提交
  36. 28 12月, 2014 2 次提交