Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Database schema evaluator from migrations as standalone project or pkg #3750

Unanswered
fira42073 asked this question in Feature Requests & Ideas
Discussion options

Hi! I wonder if it would make sense to export this structure in a public package?

I myself have a couple of ideas where I'd need some database schema and I'd generate some stuff from it. I recognize that it may be wildly out of scope for this project, but the code is kinda already there, so it would be cool just to export it as-is for other tools to potentially use.

One of them that would potentially benefit from it is tbls. Right now, you have to establish a connection to a database, and the generation usually looks something like this

DSN = "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable"
.PHONY: generate-db-docs
generate-db-docs: db wait-db migrate-up
	if [ -d "docs/db" ]; then rm -rf docs/db; fi
	tbls --config .tbls.yaml doc
	$(MAKE) db-down
.PHONY: wait-db
wait-db:
	@until docker exec t_postgres pg_isready -U postgres -h localhost -p 5432; do sleep 3; done
.PHONY: db
db:
	docker run -d --name t_postgres -e POSTGRES_USER=postgres -e POSTGRES_DB=postgres -e POSTGRES_PASSWORD=postgres --network=host postgres || true
.PHONY: db-down
db-down:
	docker rm -f t_postgres
.PHONY: migrate-up
migrate-up:
	dbmate -u $(DSN) up

which means somehow provisioning the database, running the migrations and then stopping it, which may be quite a bit cumbersome.

On the other hand, I'm not sure if the existing Schema structure from internal/catalog provides all of the required types and data to the tbls to actually generate the documentation. For example it might rely on some comments or other database objects that are not relevant in scope of sqlc.

Anyway, please let me know what you think of all of this.

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /