From 1e60167d876b05ea270a01094badcd7ffa0fa323 Mon Sep 17 00:00:00 2001 From: izavits Date: Thu, 8 Sep 2016 14:35:23 +0300 Subject: [PATCH] Add sys period field by default in create table --- CHANGELOG.md | 1 + lf-to-abstract-sql.ometajs | 1 + test/sbvr-helper.coffee | 10 +++++++++- test/students.coffee | 2 +- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e40ce7b..713d5c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +* Added a `sys period` field by default that is a `Date Time Range` with `DEFAULT [CURRENT_TIMESTAMP, )`. * Added a test for a self-referential fact type and synonymous form. v0.0.18 diff --git a/lf-to-abstract-sql.ometajs b/lf-to-abstract-sql.ometajs index e7269fd..d2f7b8f 100644 --- a/lf-to-abstract-sql.ometajs +++ b/lf-to-abstract-sql.ometajs @@ -684,6 +684,7 @@ export ometa LF2AbstractSQL <: SBVRCompilerLibs { CreateTable = {{fields: [], primitive: false, name: null, indexes: [], idField: null}}:table AddTableField(table, 'created at', 'Date Time', true, null, null, 'CURRENT_TIMESTAMP') + AddTableField(table, 'sys period', 'Date Time Range', true, null, null, 'tstzrange(CURRENT_TIMESTAMP, null)') -> table } diff --git a/test/sbvr-helper.coffee b/test/sbvr-helper.coffee index c8d6d7f..8fd8b63 100644 --- a/test/sbvr-helper.coffee +++ b/test/sbvr-helper.coffee @@ -29,6 +29,13 @@ createdAtField = index: null references: null defaultValue: 'CURRENT_TIMESTAMP' +sysPeriodField = + dataType: 'Date Time Range' + fieldName: 'sys period' + required: true + index: null + references: null + defaultValue: 'tstzrange(CURRENT_TIMESTAMP, null)' exports.TableSpace = -> tables = {} @@ -76,7 +83,7 @@ exports.TableSpace = -> currentTable = this idField = 'id' - fields = [createdAtField] + fields = [createdAtField, sysPeriodField] indexes = [] switch lf[0] when 'Term' @@ -173,6 +180,7 @@ exports.TableSpace = -> referenceScheme: typeName fields: [ createdAtField + sysPeriodField primitiveField ] else diff --git a/test/students.coffee b/test/students.coffee index 46a7d2b..f93fe09 100644 --- a/test/students.coffee +++ b/test/students.coffee @@ -31,7 +31,7 @@ describe 'students', -> # Necessity: each school year enrollment is for exactly one age. test attribute necessity 'each', schoolYearEnrollment, verb('is for'), ['at most', 'one'], age test { - property: 'tables.school_year_enrollment.fields[3].required' + property: 'tables.school_year_enrollment.fields[4].required' matches: false se: '-- should have set the age to not required' }