lfittl / activerecord-clean-db-structure Goto Github PK
View Code? Open in Web Editor NEWAutomatic cleanup for the Rails db/structure.sql file (ActiveRecord/PostgreSQL)
License: BSD 3-Clause "New" or "Revised" License
Automatic cleanup for the Rails db/structure.sql file (ActiveRecord/PostgreSQL)
License: BSD 3-Clause "New" or "Revised" License
Hi, nice gem! The only thing we constantly run into is merge conflicts of branches when 2 people added new database migrations. At the bottom of the structure.sql there will be different versions which end with a semicolon.
The versions are currently listed as follows:
INSERT INTO "schema_migrations" (version) VALUES
('20190503120501'),
('20190506124902'),
('20190508123941'),
('20190508132644');
I think we can prevent a lot of merge conflicts if we uglify this a bit:
INSERT INTO "schema_migrations" (version) VALUES
('20190503120501')
,('20190506124902')
,('20190508123941')
,('20190508132644')
;
Let me know what you think. I can create a PR for this if you like.
Maybe you should add a property to allow removal or keeping the extensions? I faced the problem where it would be very useful. For instance:
config.activerecord_clean_db_structure.ignore_extensions = true
or
config.activerecord_clean_db_structure.remove_extensions = false
Since moving to PG 10, FKs are not getting public.
schema name cleaned up:
-ALTER TABLE ONLY dude_logs
- ADD CONSTRAINT fk_rails_a1ad125ad2 FOREIGN KEY (dude_id) REFERENCES dudes(id);
+ALTER TABLE ONLY public.dude_logs
+ ADD CONSTRAINT fk_rails_a1ad125ad2 FOREIGN KEY (dude_id) REFERENCES public.dudes(id);
Another minor addition with search_path
setting at top of file.
+SELECT pg_catalog.set_config('search_path', '', false);
I can certainly give a shot fixing this, but my regex-fu is admittedly a bit rusty, I might just cause us both more work!
https://www.postgresql.org/docs/9.6/static/sql-createforeigntable.html
FOREIGN TABLE not support SERIAL PRIMARY KEY
maybe replace
dump.gsub!(/^ id integer NOT NULL,$/, ' id SERIAL PRIMARY KEY,')
by
dump.gsub!(/^CREATE TABLE (\w+) \(\n id integer NOT NULL,$/, "CREATE TABLE \\1 (\n id SERIAL PRIMARY KEY,")
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.