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

Schema dumper assumes that enum values will not contain spaces #3

Closed
AndrewSpeed opened this issue Sep 27, 2019 · 4 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@AndrewSpeed
Copy link
Contributor

AndrewSpeed commented Sep 27, 2019

Hi 👋

I've been using activerecord-pg_enum for a few weeks now, it's a fantastic gem, thanks for writing it.

Today I was adding a migration to create an enum which has values containing spaces, but the dumper doesn't appear to handle this correctly.

I've been taking a look at the codebase and would be happy to try and make this change, assuming it's deemed valid.

Steps to reproduce

Rails version: 5.2.2.1
Ruby version: 2.6.3
activerecord-pg_enum version: 1.0.2

Migration

# frozen_string_literal: true

class AddStatusEnum < ActiveRecord::Migration[5.2]
  def up
    create_enum 'status', ['sick', 'on vacation', 'working from home']
  end

  def down
    drop_enum 'status'
  end
end

Schema

Expected Schema

ActiveRecord::Schema.define(version: 2019_09_27_145140) do
  # ...

  # These are custom enum types that must be created before they can be used in the schema definition
  create_enum "status", ['sick', 'on vacation', 'working from home']
end

Actual Schema

ActiveRecord::Schema.define(version: 2019_09_27_145140) do
  # ...

  # These are custom enum types that must be created before they can be used in the schema definition
  create_enum "status", %w[sick on vacation working from home]
end

This ☝️will lead to the enum being created with values ["sick", "on", "vacation", "working", "from", "home"]

@alassek alassek added the bug Something isn't working label Oct 2, 2019
@alassek alassek self-assigned this Oct 2, 2019
@alassek
Copy link
Owner

alassek commented Oct 2, 2019

@AndrewSpeed thanks for the bug report, I hadn't even considered making enums with spaces, but you're absolutely right that they are allowed.

@alassek
Copy link
Owner

alassek commented Oct 2, 2019

If you'd like to take a crack at this, it shouldn't be very difficult; the code is here:
https://github.com/alassek/activerecord-pg_enum/blob/master/lib/active_record/pg_enum/4.1/schema_dumper.rb#L22
Otherwise I can handle it

@AndrewSpeed
Copy link
Contributor Author

👍 thanks for the response @alassek, I'll have a go at this and let you know if I run into any problems

@alassek
Copy link
Owner

alassek commented Oct 13, 2019

Fixed in v1.0.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants