hamsql: Interpreter for SQL-structure definitions in YAML (YamSql)

[ database, gpl, library, program ] [ Propose Tags ]
Versions [RSS],,
Change log CHANGELOG
Dependencies aeson (>=1.0 && <1.1), base (>=4.8 && <5.0), bytestring (>=0.10 && <0.11), containers (>=0.5 && <0.6), directory (>=1.2 && <1.3), doctemplates (>=0.1 && <0.2), file-embed (>=0.0 && <0.1), filepath (>=1.4 && <1.5), frontmatter (>=0.1 && <0.2), groom (>=0.1 && <0.2), hamsql, network-uri (>=2.6 && <2.7), optparse-applicative (>=0.13 && <0.14), postgresql-simple (>=0.4 && <0.6), text (>=1.2 && <1.3), transformers (>=0.5 && <0.6), unordered-containers (>=0.2 && <0.3), yaml (>=0.8 && <0.9) [details]
License GPL-3.0-only
Copyright (c) 2014-2016 Michael Herold et al.
Author Michael Herold <quabla@hemio.de>
Maintainer Michael Herold <quabla@hemio.de>
Category Database
Home page https://git.hemio.de/hemio/hamsql
Bug tracker https://git.hemio.de/hemio/hamsql/issues
Source repo head: git clone git@git.hemio.de:hemio/hamsql.git
Uploaded by quabla at 2016-10-27T17:02:09Z
Executables hamsql
Downloads 1866 total (6 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2016-10-29 [all 1 reports]

Readme for hamsql-

[back to package description]


An interpreter for SQL structure definitions in YAML (YamSql)

build status Hackage-Deps Hackage

About HamSql

HamSql is a software that parses SQL structures defined in a YAML based language and deploys them on PostgreSQL servers. It allows to maintain PostgreSQL projects in a form more similar to other programming languages.

In contrast to the CREATE OR REPLACE FUNCTION approaches, residual structures are deleted, column properties are deleted without explicit definition of the migration and the ordering imposed by dependencies is resolved automatically.

HamSql is on hackage, which means you can build it with cabal install hamsql. Please note the build requirements and details at the bottom. HamSql binaries for Linux amd64 are available as build artifacts from our build server.

HamSql can be used for

  • Neat SQL development with clearer versioning via "one object one file" principle
  • More flexible development with features like function and table templates
  • On site deployments of SQL structures
  • Off-line computation of upgrade strategies for known status quo
  • Documentation generation of SQL structures and APIs

What is there

  • hamsql install command that deploys the defined structure
  • hamsql upgrade command that updates existing structures
    • Per default no data are at risk during upgrade (no column/table deletion)
    • Overwrite via --permit-data-deletion possible
    • SQL command ordering that avoids dependency conflicts
    • Complicated dependencies are resolved via trial and error
  • hamsql doc creates a documentation of the complete sql structure
  • Code basis tailored for the support of many SQL features
  • Basic documentation of the YamSql Language

Coming soon

  • Support for views and triggers
  • Warn about name conflicts for SQL objects before deployment
  • Output defining YamSql file for each type of error

What is missing

Those are all things on the radar but the exact requirements are unclear or the workforce is missing.

  • Support for several other PostgreSQL features
  • Stable definition of YamSql
  • Support for renaming tables and columns
  • Covering other strategies required for upgrade
  • Unit and integration test as part of YamSql
    • Define scenarios that are loaded into the database
    • Define test and expected result for a function for a scenario
    • Define operations with expected outcome (to tests triggers etc.)

Example Project

The example project below could be deployed via

hamsql install -c postgresql:///dbname

Later changes can be pushed via

hamsql upgrade -c postgresql:///dbname

The default documentation can be written to docs/ via

hamsql doc

You can have a look at the output rendered via Sphinx.

Those are the YamSql files for the project:

# setup.yml
 - math
 - schemas
# schema/math/schema.yml
name: math
description: |
 Some basic math in SQL
# schema/math/function.d/factorial.plsql
name: factorial
description: |
 Factorial function using the
 ``WITH RECURSIVE`` SQL feature.

 Logical definition::

     f(0) = 1
     f(n) = n * f (n - 1)

 - name: p_n
   type: int
returns: int
      SELECT 1 AS f, 0 AS n
      SELECT f * (n + 1), n + 1 FROM t
# schema/math/function.d/erf.py
name: erf 
description: |
 Gauss error function

 This function is a wrapper for the
 Python 3 implementation.

 - name: x
   type: float
returns: float

language: plpython3u
import math
return math.erf(x)

Building HamSql on Debian Stretch

To completely build HamSql from source

apt install make ghc cabal-install libpq-dev happy
make install

To avoid compiling all the dependencies you can use the following set of debian packages instead of the above ones

apt install \
 make \
 ghc \
 cabal-install \
 libghc-aeson-dev \
 libghc-file-embed-dev \
 libghc-network-uri-dev \
 libghc-optparse-applicative-dev \
 libghc-pandoc-dev \
 libghc-postgresql-simple-dev \
 libghc-text-dev \
 libghc-unordered-containers-dev \