Skip to content

Comments

Default engine ENGINE=InnoDB is no longer dumped to make schema more agnostic#39365

Merged
kamipo merged 2 commits intorails:masterfrom
kamipo:table_options
May 24, 2020
Merged

Default engine ENGINE=InnoDB is no longer dumped to make schema more agnostic#39365
kamipo merged 2 commits intorails:masterfrom
kamipo:table_options

Conversation

@kamipo
Copy link
Member

@kamipo kamipo commented May 20, 2020

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:

create_table "accounts", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", force: :cascade do |t|
end

After:

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.

…e agnostic

5 years ago, I made dumping full table options at rails#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 rails#26209.
Closes rails#29472.

See also rails#33608, rails#33853, and rails#34742.
Otherwise we cannot handle the same name options for both column and
table (e.g. `:comment`, `:charset`, `:collation`).
@kamipo kamipo merged commit e7317a2 into rails:master May 24, 2020
@kamipo kamipo deleted the table_options branch May 24, 2020 00:27
yahonda added a commit to rsim/oracle-enhanced that referenced this pull request May 25, 2020
yahonda added a commit to yahonda/oracle-enhanced that referenced this pull request Sep 10, 2020
This pull request restores Schema Dumper behavior changed by rsim#2019
because rails/rails#39365 does not intend to dump the default primary key configuration.

Related to rails/rails#39365
Follow up rsim#2019
yahonda added a commit to yahonda/oracle-enhanced that referenced this pull request Sep 10, 2020
This pull request restores Schema Dumper behavior changed by rsim#2019
because rails/rails#39365 does not intend to dump the default primary key configuration.

Related to rails/rails#39365
Follow up rsim#2019
yahonda added a commit to yahonda/oracle-enhanced that referenced this pull request Sep 11, 2020
This pull request restores Schema Dumper behavior changed by rsim#2019
because rails/rails#39365 does not intend to dump the default primary key configuration.

To avoid hash creation every time, it has been frozen and saved as a
constant.

Related to rails/rails#39365
Follow up rsim#2019
Refer http://code.jeremyevans.net/presentations/rubykaigi2019/index.html#58
yahonda added a commit to yahonda/oracle-enhanced that referenced this pull request Sep 11, 2020
This pull request restores Schema Dumper behavior changed by rsim#2019
because rails/rails#39365 does not intend to dump the default primary key configuration.

To avoid hash creation every time, it has been frozen and saved as a
constant.

Related to rails/rails#39365
Follow up rsim#2019
Refer http://code.jeremyevans.net/presentations/rubykaigi2019/index.html#58
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Dec 27, 2020
table options are parsed charset/collation in 6.1.0.
related: rails/rails#39365

```
// before
// < 6.1.0
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci" do |t|
end

// after
// >= 6.1.0
create_table "users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci" do |t|
end
```

If `dump_without_table_options` is disabled, ridgepole doesn't dump charset/collation.
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Dec 27, 2020
In 6.1, table options are parsed to charset/collation. rails/rails#39365
The following cases should be same result.

```
create_table "items", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci" do |t|
end

create_table "items", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci" do |t|
end
```

To solve this I handled that if new-style `charset/collation` given, it
converts to old-style `options`. By doing so, I solved the problem by a little changes.

https://github.com/rails/rails/pull/39365/files#diff-868f1dccfcbed26a288bf9f3fd8a39c863a4413ab0075e12b6805d9798f556d1R427
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Dec 27, 2020
rails/rails#39365 introduced new-style id options like the followings.

```
// < 6.1 old-style
create_table(:items, id: :bigint, unsigned: true) {}

// >= 6.1 new-style
create_table(:items, id: { type: :bigint, unsigned: true }) {}
```

To compare those styles to get diff, I handled that I normalizes id options
from those styles.
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Dec 27, 2020
table options are parsed charset/collation in 6.1.0.
related: rails/rails#39365

```
// before
// < 6.1.0
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci" do |t|
end

// after
// >= 6.1.0
create_table "users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci" do |t|
end
```

If `dump_without_table_options` is disabled, ridgepole doesn't dump charset/collation.
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Dec 27, 2020
In 6.1, table options are parsed to charset/collation. rails/rails#39365
The following cases should be same result.

```
create_table "items", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci" do |t|
end

create_table "items", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci" do |t|
end
```

To solve this I handled that if new-style `charset/collation` given, it
converts to old-style `options`. By doing so, I solved the problem by a little changes.

https://github.com/rails/rails/pull/39365/files#diff-868f1dccfcbed26a288bf9f3fd8a39c863a4413ab0075e12b6805d9798f556d1R427
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Dec 27, 2020
rails/rails#39365 introduced new-style id options like the followings.

```
// < 6.1 old-style
create_table(:items, id: :bigint, unsigned: true) {}

// >= 6.1 new-style
create_table(:items, id: { type: :bigint, unsigned: true }) {}
```

To compare those styles to get diff, I handled that I normalizes id options
from those styles.
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Dec 27, 2020
rails/rails#39365 introduced new-style id options like the followings.

```
// < 6.1 old-style
create_table(:items, id: :bigint, unsigned: true) {}

// >= 6.1 new-style
create_table(:items, id: { type: :bigint, unsigned: true }) {}
```

To compare those styles to get diff, I handled that I normalizes id options
from those styles.
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Dec 27, 2020
rails/rails#39365 introduced new-style id options like the followings.

```
// < 6.1 old-style
create_table(:items, id: :bigint, unsigned: true) {}

// >= 6.1 new-style
create_table(:items, id: { type: :bigint, unsigned: true }) {}
```

To compare those styles to get diff, I handled that I normalizes id options
from those styles.
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Dec 27, 2020
rails/rails#39365 introduced new-style id options like the followings.

```
// < 6.1 old-style
create_table(:items, id: :bigint, unsigned: true) {}

// >= 6.1 new-style
create_table(:items, id: { type: :bigint, unsigned: true }) {}
```

To compare those styles to get diff, I handled that I normalizes id options
from those styles.
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Dec 27, 2020
rails/rails#39365 introduced new-style id options like the followings.

```
// < 6.1 old-style
create_table(:items, id: :bigint, unsigned: true) {}

// >= 6.1 new-style
create_table(:items, id: { type: :bigint, unsigned: true }) {}
```

To compare those styles to get diff, I handled that I normalizes id options
from those styles.
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Dec 28, 2020
table options are parsed charset/collation in 6.1.0.
related: rails/rails#39365

```
// before
// < 6.1.0
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci" do |t|
end

// after
// >= 6.1.0
create_table "users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci" do |t|
end
```

If `dump_without_table_options` is disabled, ridgepole doesn't dump charset/collation.
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Dec 28, 2020
In 6.1, table options are parsed to charset/collation. rails/rails#39365
The following cases should be same result.

```
create_table "items", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci" do |t|
end

create_table "items", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci" do |t|
end
```

To solve this I handled that if new-style `charset/collation` given, it
converts to old-style `options`. By doing so, I solved the problem by a little changes.

https://github.com/rails/rails/pull/39365/files#diff-868f1dccfcbed26a288bf9f3fd8a39c863a4413ab0075e12b6805d9798f556d1R427
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Dec 28, 2020
rails/rails#39365 introduced new-style id options like the followings.

```
// < 6.1 old-style
create_table(:items, id: :bigint, unsigned: true) {}

// >= 6.1 new-style
create_table(:items, id: { type: :bigint, unsigned: true }) {}
```

To compare those styles to get diff, I handled that I normalizes id options
from those styles.
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Jan 1, 2021
table options are parsed charset/collation in 6.1.0.
related: rails/rails#39365

```
// before
// < 6.1.0
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci" do |t|
end

// after
// >= 6.1.0
create_table "users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci" do |t|
end
```

If `dump_without_table_options` is disabled, ridgepole doesn't dump charset/collation.
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Jan 1, 2021
In 6.1, table options are parsed to charset/collation. rails/rails#39365
The following cases should be same result.

```
create_table "items", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci" do |t|
end

create_table "items", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci" do |t|
end
```

To solve this I handled that if new-style `charset/collation` given, it
converts to old-style `options`. By doing so, I solved the problem by a little changes.

https://github.com/rails/rails/pull/39365/files#diff-868f1dccfcbed26a288bf9f3fd8a39c863a4413ab0075e12b6805d9798f556d1R427
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Jan 1, 2021
rails/rails#39365 introduced new-style id options like the followings.

```
// < 6.1 old-style
create_table(:items, id: :bigint, unsigned: true) {}

// >= 6.1 new-style
create_table(:items, id: { type: :bigint, unsigned: true }) {}
```

To compare those styles to get diff, I handled that I normalizes id options
from those styles.
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Jan 1, 2021
table options are parsed charset/collation in 6.1.0.
related: rails/rails#39365

```
// before
// < 6.1.0
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci" do |t|
end

// after
// >= 6.1.0
create_table "users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci" do |t|
end
```

If `dump_without_table_options` is disabled, ridgepole doesn't dump charset/collation.
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Jan 1, 2021
In 6.1, table options are parsed to charset/collation. rails/rails#39365
The following cases should be same result.

```
create_table "items", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci" do |t|
end

create_table "items", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci" do |t|
end
```

To solve this I handled that if new-style `charset/collation` given, it
converts to old-style `options`. By doing so, I solved the problem by a little changes.

https://github.com/rails/rails/pull/39365/files#diff-868f1dccfcbed26a288bf9f3fd8a39c863a4413ab0075e12b6805d9798f556d1R427
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Jan 1, 2021
rails/rails#39365 introduced new-style id options like the followings.

```
// < 6.1 old-style
create_table(:items, id: :bigint, unsigned: true) {}

// >= 6.1 new-style
create_table(:items, id: { type: :bigint, unsigned: true }) {}
```

To compare those styles to get diff, I handled that I normalizes id options
from those styles.
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Jan 1, 2021
table options are parsed charset/collation in 6.1.0.
related: rails/rails#39365

```
// before
// < 6.1.0
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci" do |t|
end

// after
// >= 6.1.0
create_table "users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci" do |t|
end
```

If `dump_without_table_options` is disabled, ridgepole doesn't dump charset/collation.
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Jan 1, 2021
In 6.1, table options are parsed to charset/collation. rails/rails#39365
The following cases should be same result.

```
create_table "items", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci" do |t|
end

create_table "items", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci" do |t|
end
```

To solve this I handled that if new-style `charset/collation` given, it
converts to old-style `options`. By doing so, I solved the problem by a little changes.

https://github.com/rails/rails/pull/39365/files#diff-868f1dccfcbed26a288bf9f3fd8a39c863a4413ab0075e12b6805d9798f556d1R427
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Jan 1, 2021
rails/rails#39365 introduced new-style id options like the followings.

```
// < 6.1 old-style
create_table(:items, id: :bigint, unsigned: true) {}

// >= 6.1 new-style
create_table(:items, id: { type: :bigint, unsigned: true }) {}
```

To compare those styles to get diff, I handled that I normalizes id options
from those styles.
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Jan 1, 2021
table options are parsed charset/collation in 6.1.0.
related: rails/rails#39365

```
// before
// < 6.1.0
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci" do |t|
end

// after
// >= 6.1.0
create_table "users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci" do |t|
end
```

If `dump_without_table_options` is disabled, ridgepole doesn't dump charset/collation.
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Jan 1, 2021
In 6.1, table options are parsed to charset/collation. rails/rails#39365
The following cases should be same result.

```
create_table "items", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci" do |t|
end

create_table "items", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci" do |t|
end
```

To solve this I handled that if new-style `charset/collation` given, it
converts to old-style `options`. By doing so, I solved the problem by a little changes.

https://github.com/rails/rails/pull/39365/files#diff-868f1dccfcbed26a288bf9f3fd8a39c863a4413ab0075e12b6805d9798f556d1R427
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Jan 1, 2021
rails/rails#39365 introduced new-style id options like the followings.

```
// < 6.1 old-style
create_table(:items, id: :bigint, unsigned: true) {}

// >= 6.1 new-style
create_table(:items, id: { type: :bigint, unsigned: true }) {}
```

To compare those styles to get diff, I handled that I normalizes id options
from those styles.
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Jan 2, 2021
table options are parsed charset/collation in 6.1.0.
related: rails/rails#39365

```
// before
// < 6.1.0
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci" do |t|
end

// after
// >= 6.1.0
create_table "users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci" do |t|
end
```

If `dump_without_table_options` is disabled, ridgepole doesn't dump charset/collation.
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Jan 2, 2021
In 6.1, table options are parsed to charset/collation. rails/rails#39365
The following cases should be same result.

```
create_table "items", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci" do |t|
end

create_table "items", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci" do |t|
end
```

To solve this I handled that if new-style `charset/collation` given, it
converts to old-style `options`. By doing so, I solved the problem by a little changes.

https://github.com/rails/rails/pull/39365/files#diff-868f1dccfcbed26a288bf9f3fd8a39c863a4413ab0075e12b6805d9798f556d1R427
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Jan 2, 2021
rails/rails#39365 introduced new-style id options like the followings.

```
// < 6.1 old-style
create_table(:items, id: :bigint, unsigned: true) {}

// >= 6.1 new-style
create_table(:items, id: { type: :bigint, unsigned: true }) {}
```

To compare those styles to get diff, I handled that I normalizes id options
from those styles.
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Jan 2, 2021
table options are parsed charset/collation in 6.1.0.
related: rails/rails#39365

```
// before
// < 6.1.0
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci" do |t|
end

// after
// >= 6.1.0
create_table "users", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci" do |t|
end
```

If `dump_without_table_options` is disabled, ridgepole doesn't dump charset/collation.
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Jan 2, 2021
In 6.1, table options are parsed to charset/collation. rails/rails#39365
The following cases should be same result.

```
create_table "items", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci" do |t|
end

create_table "items", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci" do |t|
end
```

To solve this I handled that if new-style `charset/collation` given, it
converts to old-style `options`. By doing so, I solved the problem by a little changes.

https://github.com/rails/rails/pull/39365/files#diff-868f1dccfcbed26a288bf9f3fd8a39c863a4413ab0075e12b6805d9798f556d1R427
alpaca-tc added a commit to alpaca-tc/ridgepole that referenced this pull request Jan 2, 2021
rails/rails#39365 introduced new-style id options like the followings.

```
// < 6.1 old-style
create_table(:items, id: :bigint, unsigned: true) {}

// >= 6.1 new-style
create_table(:items, id: { type: :bigint, unsigned: true }) {}
```

To compare those styles to get diff, I handled that I normalizes id options
from those styles.
y-yagi added a commit to y-yagi/ridgepole that referenced this pull request Aug 24, 2025
`ridgepole` doesn't know indexes that created by automatically.
So checking to avoid those.
https://github.com/ridgepole/ridgepole/blob/4a18cef152027d1d02a6f7bb004c9c32d09bb581/lib/ridgepole/dsl_parser.rb#L33-L46

This check depends on `ENGINE=InnoDB` option.
But, since Rails 6.1, Rails doesn't output it by default.
rails/rails#39365
So the current check doesn't work as expected.

This PR fixed to check foreign key when table options is nil or InnoDB.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rails 5 schema.rb adding non-agnostic options. dev mysql -> test sqlite

1 participant