mirror of
https://github.com/xataio/pgroll.git
synced 2024-09-11 13:55:28 +03:00
Build on #344 to allow removing column comments by setting them to `null`. Make use of https://github.com/omissis/go-jsonschema/pull/220 and use the [nullable](https://github.com/oapi-codegen/nullable) package so that it's possible to distingush between a missing `comment` field and one that is explicitly set to `null`. With https://github.com/omissis/go-jsonschema/pull/220 not being part of a release yet, use a custom build of `go-jsonschema`. It should be possible to switch back to the official release images once https://github.com/omissis/go-jsonschema/pull/220 is part of a release. Without this change it becomes impossible to remove a comment from a column using the 'set comment' 'alter column' sub-operation (https://github.com/xataio/pgroll/pull/344).
15 lines
913 B
Makefile
15 lines
913 B
Makefile
.PHONY: generate
|
|
generate:
|
|
# Format JSON schema
|
|
docker run --rm -v $$PWD/schema.json:/mnt/schema.json node:alpine npx prettier /mnt/schema.json --parser json --tab-width 2 --single-quote --trailing-comma all --no-semi --arrow-parens always --print-width 120 > schema.json.tmp
|
|
mv schema.json.tmp schema.json
|
|
|
|
# Generate the types from the JSON schema
|
|
# Temporarily use the `surjection/go-jsonschema` image because we need https://github.com/omissis/go-jsonschema/pull/220
|
|
# Use the official `omissis/gojsonschema` image once 0.17.0 is released.
|
|
docker run --rm -v $$PWD/schema.json:/mnt/schema.json surjection/go-jsonschema:0.16.1 --only-models -p migrations --tags json /mnt/schema.json > pkg/migrations/types.go
|
|
|
|
# Add the license header
|
|
echo "// SPDX-License-Identifier: Apache-2.0" | cat - pkg/migrations/types.go > pkg/migrations/types.go.tmp
|
|
mv pkg/migrations/types.go.tmp pkg/migrations/types.go
|