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 Libraries Top

hpopp
After just over two years in development, this latest version of Pigeon is what I finally consider done in regards to my original vision ...
New
tompave
Hello there, I would like to share a feature toggles library (AKA feature flags) I’ve been working on. The main package is FunWithFlags...
New
sasajuric
I’d like to announce a small library called boundaries. This is an experimental project which explores the idea of enforcing boundaries ...
New
mbuhot
Leverage Open Api 3.0 (Swagger) to document, test, validate and explore your Plug and Phoenix APIs. Generate and serve a JSON Open API ...
New
michalmuskala
Hello everybody. I have just released Jason - a new JSON library. You might be wondering, why do we need a new library? The primary foc...
New
Jskalc
Hi! Today, after a couple weeks of development I’ve released v0.1 of LiveVue. It’s a seamless integration of Vue and Phoenix LiveView, i...
New
zorbash
I created Kitto a framework for dashboards inspired by Dashing. [demo] The distributed characteristics of Elixir and the low memory foo...
New
tmbb
PhoenixWS - Websockets over Phoenix Channels Source code on Github here: https://github.com/tmbb/phoenix_ws Phoenix channels are a great...
New
vic
Expat is a tiny experiment I did for extracting patterns and being able to reuse them (compose and share patterns between elixir librarie...
New
mischov
import Meeseeks.CSS html = HTTPoison.get!("https://news.ycombinator.com/").body for story <- Meeseeks.all(html, css("tr.athing")) do...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

Sub Categories:

We're in Beta

About us Mission Statement