theanurin/sqlmigrationbuilder

By theanurin

Updated almost 2 years ago

SQL Migration Builder - is a processor of Mustache based SQL script templates.

Image
0

10K+

theanurin/sqlmigrationbuilder repository overview

Docker Image Version Docker Image Size GitHub Workflow Status GitHub Repo Stars Docker Pulls Docker Stars

SQL Migration Builder

SQL Migration Builder - is a processor of Mustache based SQL script templates.

Image reason

TDB

Spec

Environment variables

  • DIST_PATH - Path to build artifacts. Relative to /data. Default: '.dist'.
  • ENV - A name of target build environment, like a: devel, test, production. Default: ''.
  • EXTRA_CONFIGS - Comma-separated list of additional configuration files. Relative to /data. Default: ''.
  • SOURCE_PATH - Path to sources. Relative to /data. Default: 'migration'.
  • VERSION_FROM - Version from. Default: '',
  • VERSION_TO - Version to. Default: ''.

Little bit of "magic"

ENV make some magic
  • Render context provides capitalized build configuration flag in format: is${capitalized(ENV)}
  • Use configuration file database-{$ENV}.config

Examples:

  • ENV=production gives isProduction: true + read database-production.config
  • ENV=test gives isTest: true + read database-test.config
  • ENV=devel gives isDevel: true + read database-devel.config

So you can use something like this:

--
-- EMULATOR kind will be produced only for non-production environments
--
CREATE TYPE "public"."SERVICE_KIND" AS ENUM (
{{^isProduction}}
	'EMULATOR',
{{/isProduction}}
	'WEBSOCKET'
);
Accessors extension s, $root and $parent
  • extension s - refer to the properties array
  • $root - refer root data context
  • $parent - refer parent data context

Example:

-- database.schema.common.name = common
-- database.schema.audit.name  = audit
--
-- database.user.readonly = "db_ro_user"
--

-- Here we iterate all schema as array. database.schemas - refers to array with all database.schema entries.
{{#database.schemas}}
CREATE SCHEMA "{{ name }}";
COMMENT ON SCHEMA "{{ name }}" IS '{{ desc }}';

-- Mustache doesn't allow you to refer to parent objects.
-- By the "magic" you are able to refer root data context
GRANT USAGE ON SCHEMA "{{ name }}" TO "{{$root.database.user.readonly}}";

-- Mustache doesn't allow you to refer to parent objects.
-- By the "magic" you are able to refer parent data context.
GRANT USAGE ON SCHEMA "{{ name }}" TO "{{$parent.user.readonly}}";
{{/database.schemas}}

Volumes

  • /data - Root your database work directory

Inside

  • Alpine Linux
  • NodeJS
  • Migration Builder JS Script

Launch

docker run --interactive --tty --rm --volume /path/to/database/workdir:/data theanurin/sqlmigrationbuilder

Support

Tag summary

Content type

Image

Digest

sha256:e091049c2

Size

29.1 MB

Last updated

almost 2 years ago

docker pull theanurin/sqlmigrationbuilder