snowplow-archive / schema-guru

JSONs -> JSON Schema
http://snowplowanalytics.com
150 stars 20 forks source link

Add SQL migrations between schema ADDITIONs #134

Closed alexanderdean closed 8 years ago

alexanderdean commented 8 years ago

Consider the link_click: https://github.com/snowplow/iglu-central/tree/master/schemas/com.snowplowanalytics.snowplow/link_click/jsonschema

When running Schema Guru against this folder, Schema Guru should generate a file:

/sql/com.snowplowanalytics.snowplow/link-click/1-0-0/1-0-1.sql

The contents of this file should be:

-- WARNING: only apply this file to your database if the following SQL returns the expected:
--
-- select pg_catalog.obj_description(c.oid) from pg_catalog.pg_class c where c.relname = 'com_snowplowanalytics_snowplow_link_click_1';
--  obj_description
-- -----------------
--  iglu:com.snowplowanalytics.snowplow/link-click/jsonschema/1-0-0
-- (1 row)

BEGIN TRANSACTION;

  ALTER TABLE atomic.com_snowplowanalytics_snowplow_link_click_1
    ADD COLUMN "element_content" VARCHAR(4096) ENCODE LZO;

  COMMENT ON TABLE "atomic"."com_snowplowanalytics_snowplow_link_click_1" IS 'iglu:com.snowplowanalytics.snowplow/link-click/jsonschema/1-0-1';

END TRANSACTION;

In the case that com.acme/eg-schema/1-0-0, /1-0-1, /1-0-2 and /1-0-3 exist, the folder structure should look like this:

    /sql/com.acme/eg-schema/1-0-0/1-0-1.sql
    /sql/com.acme/eg-schema/1-0-0/1-0-2.sql
    /sql/com.acme/eg-schema/1-0-0/1-0-3.sql
    /sql/com.acme/eg-schema/1-0-1/1-0-2.sql
    /sql/com.acme/eg-schema/1-0-1/1-0-3.sql
    /sql/com.acme/eg-schema/1-0-2/1-0-3.sql

In other words, it should be possible to always be possible to upgrade to the latest ADDITION using a single script.

alexanderdean commented 8 years ago

Feedback @lesjonesiv, @yalisassoon, @chuwy ?