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

when using activerecord 5 schema_format = :sql still outputs to schema.rb #129

Closed
kjg opened this issue Dec 21, 2016 · 9 comments
Closed

Comments

@kjg
Copy link

kjg commented Dec 21, 2016

I just started a new project with standalone-migrations and activerecord 5. I set the schema_format = :sql, but the file created during migrations is still at schema.rb The contents of the file IS SQL however.

Using standalone-migrations with active record 4.2 properly puts the sql in structure.sql, as does running migrations on a fresh Rails 5 install.

It appears that something about the way standalone-migrations interacts with rails 5 causes active record to output the sql to the wrong file

@kjg
Copy link
Author

kjg commented Dec 21, 2016

It looks like it is because of this change rails/rails@99e57a8 in which structure dumps now use the path in ENV['SCHEMA'] if set and standalone-migrations sets ENV['SCHEMA'] to db/schema.rb by default.

@twobitlabs
Copy link
Collaborator

Can you test with our newest version 5.2.0? If if doesn't work for you we'd love a PR with a fix!

@kjg
Copy link
Author

kjg commented Apr 28, 2017

Unfortunately I no longer use standalone-migrations day to day, but I would guess a fix might involve changing this line, and it says it hasn't been touched in 3 years.

Did you make a change that you expect to have fixed this issue? I'd be happy to take a look.

Thanks!

@twobitlabs
Copy link
Collaborator

No worries, I just wanted to make sure the issue didn't get left behind. I'll leave this issue open and if someone else comes along that needs that feature they can send a PR with a fix. Standalone migrations is maintained by its active users now and we just review PR's and publish updates when new PR's are merged.

@konstantinn
Copy link

konstantinn commented Sep 4, 2017

Can confirm bug still exists on ~> 5.2.3
schema.rb is generated whatever schema_format is.

Works like this:

ENV['SCHEMA'] = "db/strucutre.sql"
ActiveRecord::Base.schema_format = :sql

@MaxGabriel
Copy link

You can workaround this by specifying the schema file name in the .standalone_migrations YAML config file:

db:
    schema: db/schema.sql

You still need to specify the ActiveRecord schema format in the Rakefile:

ActiveRecord::Base.schema_format = :sql

@jmehnle
Copy link
Contributor

jmehnle commented Mar 19, 2018

The line of code …

      ENV['SCHEMA'] = schema

was originally introduced in #42. I'm not familiar enough with today's Rails/ActiveRecord code to come up with a better solution, but I figure there might be a way to hook into Rails/AR in such a way that allows us to override the path (but not the base name) of the schema/structure dump file. Then we wouldn't have to explicitly set the SCHEMA environment variable.

jmehnle pushed a commit to jmehnle/standalone-migrations that referenced this issue Mar 19, 2018
…icitly specified in config file.

This allows ActiveRecord to choose between `schema.rb` and `structure.sql` as the file name, and setting `ActiveRecord::Base.schema_format = :sql` will actually dump to the right file (`structure.sql`).

This should address <thuss#129>.
jmehnle pushed a commit to jmehnle/standalone-migrations that referenced this issue Mar 19, 2018
…ver ActiveRecord defaults to.

This allows ActiveRecord to choose between `schema.rb` and `structure.sql` as the file name, and setting `ActiveRecord::Base.schema_format = :sql` will actually dump to the right file (`structure.sql`).

This should address <thuss#129>.
@jmehnle
Copy link
Contributor

jmehnle commented Mar 19, 2018

I believe PR #141 addresses this in a better way.

@twobitlabs
Copy link
Collaborator

Merged PR #141 and published v5.2.4. Thanks @jmehnle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants