Skip to content
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

chiastolite
Copy link
Contributor

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?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you mention about column_type in the error message?

@kamipo
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
Copy link
Contributor Author

rebased & update error message.

@kamipo kamipo merged commit 0914ea8 into rails:master Feb 9, 2019
kamipo added a commit that referenced this pull request Feb 9, 2019
…names

Do not allow to add column without column name
@kamipo
Copy link
Member

kamipo commented Feb 9, 2019

Thanks!

@chiastolite chiastolite deleted the add_column_without_column_names branch February 10, 2019 00:33
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.

None yet

2 participants