egze

egze

StructureSqlFormatter - clean away all the unnecessary output in structure.sql every time you run mix format

Hi everyone,

I wrote a small formatter to make diffs of structure.sql for postgres more readable.

StructureSqlFormatter
GitHub

Context: I’m a fan of committing structure.sql together with the pull request. If working with a team, there are sometimes merge conflicts, and in general it can be hard to read the changes for reviewers. The formatter aims to fix it and produce a more clean file.

It removes all the unneeded things, for example the lines with specific postgres version (because developers often have different versions)

Example:

--- Dumped from database version 14.5
--- Dumped by pg_dump version 16.1

Or removes unneeded comments:
Before:

--
-- Name: public; Type: SCHEMA; Schema: -; Owner: -
--

After

-- Name: public; Type: SCHEMA

Also it changes the lines with the list of applied migrations:

-
-INSERT INTO public."schema_migrations" (version) VALUES (20231213193252);
-INSERT INTO public."schema_migrations" (version) VALUES (20231213194556);
-INSERT INTO public."schema_migrations" (version) VALUES (20231213205552);
-INSERT INTO public."schema_migrations" (version) VALUES (20231214132216);
-INSERT INTO public."schema_migrations" (version) VALUES (20231214162040);
-INSERT INTO public."schema_migrations" (version) VALUES (20231214165232);
+
+INSERT INTO public."schema_migrations" (version) VALUES
+ (20231213193252)
+,(20231213194556)
+,(20231213205552)
+,(20231214132216)
+,(20231214162040)
+,(20231214165232)
+;

Then for each migration there will only be a diff of 1 added line.

All options are configurable too!

It is inspired by lfittl/activerecord-clean-db-structure, I mostly reimplemented the regexpes in Elixir and changed some small things here and there.

Most Liked

dimitarvp

dimitarvp

This is very useful, thanks for making it.

Where Next?

Popular in Announcing Top

tmbb
I’ve published the first version of my Makeup library. It’s a syntax highlighter for Elixir in the spirit of Pygments, Currently it highl...
New
josevalim
Hi everyone, We would like to announce that Plataformatec is working on a new MySQL driver called MyXQL. Our goal is to eventually integ...
New
devonestes
Introducing assertions, the library that helps you write really great test assertions! GitHub: https://github.com/devonestes/assertions ...
New
gabrielpoca
Hello everyone! I want to share with you something that I’m really proud of: https://stillstatic.io/ Still is a static site builder for...
New
mspanc
I am pleased to announce an initial release of the Membrane Framework - an Elixir-based framework with special focus on processing multim...
New
tmbb
I’ve been working on two packages (not on hex.pm yet) to build admin interfaces for phoenix apps: bureaucrat - which contains a bunch ...
New
oltarasenko
Dear Elixir community, After a year of development, bug fixes, and improvements, we are proudly ready to share the release of Crawly 0.1...
New
ahamez
Hi everyone, I’ve been working on this protobuf library for 3 years. We use it in the company I work for, EasyMile, to communicate with ...
New
markmark206
simple_feature_flags is a tiny package that lets you turn features on or off based on which environment (e.g. localhost, staging, product...
New
wfgilman
I’ve cleaned up and open sourced three financial libraries I was using for my company. They are bindings for the APIs of these three comp...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29305 241
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52238 488
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New

We're in Beta

About us Mission Statement