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

pkrawat1
Hey guyz We at @aviabird are working on a payment library in elixir/phoenix. We are targeting March 2018 to add 56 Gateways to it. Have...
New
mathieuprog
Hello :waving_hand: Allow me to introduce you to Tz, an alternative time zone database support to Tzdata. Why another library? First a...
New
wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 10719 134
New
martinthenth
Hello everybody :wave: Recently, some of my colleagues talked about database ids and uuids and their problems, and I remembered the pain...
New
brainlid
LangChain is short for Language Chain. An LLM, or Large Language Model, is the “Language” part. This library makes it easier for Elixir a...
New
scohen
Lexical Lexical is a next-generation language server for the Elixir programming language. Features Context aware code completion As-you...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

We're in Beta

About us Mission Statement