New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not allow to add column without column name #35203

Merged
merged 1 commit into from Feb 9, 2019

Conversation

Projects
None yet
2 participants
@chiastolite
Copy link
Contributor

chiastolite commented Feb 9, 2019

I applied the following migration.

create_table "users" do |t|
  t.string :name
  t.timestamp
end

It contains a typo, timestamp instead of timestamps.
But this is appliable without errors.

Short-hands for TableDefinition#columns is callable without column names.
It do nothing when called without column names.
This change suggests raise ArgumentError in such cases.

@@ -230,6 +230,7 @@ def primary_key(name, type = :primary_key, **options)
].each do |column_type|
module_eval <<-CODE, __FILE__, __LINE__ + 1
def #{column_type}(*args, **options)
raise ArgumentError, "Missing column name(s)" if args.empty?

This comment has been minimized.

@kamipo

kamipo Feb 9, 2019

Member

Can you mention about column_type in the error message?

@kamipo

This comment has been minimized.

Copy link
Member

kamipo commented Feb 9, 2019

I've extracted define_column_methods to ease to handle all short-hand methods at c7721ea.
Can you rebase on master?

@chiastolite chiastolite force-pushed the chiastolite:add_column_without_column_names branch from 77ef77c to 0914ea8 Feb 9, 2019

@rails-bot rails-bot bot added the activerecord label Feb 9, 2019

@chiastolite

This comment has been minimized.

Copy link
Contributor Author

chiastolite commented Feb 9, 2019

rebased & update error message.

@kamipo kamipo merged commit 0914ea8 into rails:master Feb 9, 2019

2 checks passed

codeclimate All good!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

kamipo added a commit that referenced this pull request Feb 9, 2019

Merge pull request #35203 from chiastolite/add_column_without_column_…
…names

Do not allow to add column without column name
@kamipo

This comment has been minimized.

Copy link
Member

kamipo commented Feb 9, 2019

Thanks!

@chiastolite chiastolite deleted the chiastolite:add_column_without_column_names branch Feb 10, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment