Comments (8)
@fj re needing hash-rocket for non-symbol keys -- I don't think that's a huge issue here, since the hash is used for column options, which are defined by reasonable humans to have reasonable names. Conceivably some nested values for some options could be arbitrary hashes though, I suppose. But still, a pretty output formatter could use symbol-colon form whenever the key is a symbol, and revert to hash-rocket only when necessary.
@braindev FWIW I'm willing to accept a PR that prettifies the output (with sufficient tests of course!), just don't have the time to do it myself right now. or perhaps following SOC, maybe somebody could write or find a simple gem that will do this, and schema_plus_core could use it.
from schema_plus.
Yes this change is a byproduct of other changes. I didn't consider it a regression or breaking change since it's functionally equivalent.
TL;DR: the simplest cleanest way that I know to print a ruby hash that contains only primitives, in a form that can be read back in as valid ruby, is simply to use the builtin Hash#to_s
-- which prints using the old Ruby format. Could write a custom dumper in some form but that seems like extra code (with more opportunities for bugs) for little functional benefit.
from schema_plus.
This seems reasonable to me too.
@nesrual, is this breaking something specific for you? If the behavior of schema_plus
changed as a result of the functionally equivalent hash changing, that's a bug. Otherwise this isn't really any different than if schema_plus decided to write:
t.string \
"foo"
instead of
t.string "foo"
from schema_plus.
@nerusal I should add that I was disappointed by this change too, since the modern style makes for clear looking output IMHO. But I couldn't justify to myself muddying the code (and taking the time) just to make the output arguably prettier.
But of course as @fj commented, if the change in output format really does break something then of course it'd need to be fixed.
from schema_plus.
Besides the output change in the schema.rb
file all works fine - so not really a "bug" in that sense. However it would be nice to keep the format of the file in the "proper" format
from schema_plus.
On further reflection, I think hash-rocket may actually be preferred. Unusual but theoretically legal database column names or property values (e.g. "!!!X&&&") might not also be legal Ruby symbol names (e.g. you can't write !!!X&&&: false
), so you would have to quote everything, which is what the Hash.to_s
method that @ronen currently implements uses.
But if you quote everything and decide to use the new-style Hash syntax, then there is an ambiguity between these three choices:
{"!foo": 1}
: key is the symbol:"!foo"
{:"!foo" => 1}
: key is the symbol:"!foo"
{"!foo" => 1}
: key is the string"!foo"
So I think not using hashrockets as the canonical representation would actually be a bug.
from schema_plus.
BTW, if you want to keep your migrations "clean", one thing I've done is perform an empty migration, commit the change, and then continue with my subsequent migrations. That isolates the commit with the schema_plus syntax changes so that the rest of your commits are clean.
from schema_plus.
FWIW,
from schema_plus.
Related Issues (20)
- Thread safety problem with schema_plus 2 / Postgres HOT 8
- Wrong index export in jsonb column HOT 2
- change_column uses default foreign key configuration instead of defined configuration causing migration to crash HOT 1
- schema_plus 1.8.x: jruby + postgresql with activerecord-jdbcpostgresql-adpater > 1.3.14 HOT 2
- When using add_column foreign key does not use the default_name method HOT 3
- Schema dump support for multiple schemas HOT 6
- doesn't work with annotate gem and MySQL and postgres
- Index name not respected when adding an index in `change_table` HOT 2
- Schema plus schema dump crashes on custom types on postgresql HOT 5
- Bug: Postgres expression index with multiple expressions runs correct SQL, but produces incorrect schema modifications HOT 2
- add_foreign_key not compatible with Activerecord version HOT 1
- All but the last `t.index` reference for a table are ignored HOT 4
- Wrong foreign_key format in schema.rb HOT 5
- Support Rails 5 HOT 9
- Issue when upgrading from Rails 4.2.5.2 to 4.2.6 HOT 5
- New gem request: Support arbitrary per-table and/or per-column metadata in schema
- Guidance with parsing CREATE sql for Sql Server HOT 3
- Support ruby +2.1 HOT 2
- nal has_many
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from schema_plus.