Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sys period field by default in create table #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions lf-to-abstract-sql.ometajs
Original file line number Diff line number Diff line change
Expand Up @@ -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)')
Copy link
Contributor

@Page- Page- Sep 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will only work for postgres? (the tstzrange(CURRENT_TIMESTAMP, null))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there another way to pass the default value and determine automatically the syntax according to the db engine? Also, mysql does not have that datatype.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not currently - it hasn't been necessary before. I guess the best way to do it would be to move the dataTypeGen function from abstract-sql-compiler to sbvr-types (I think it makes a lot more sense to be there, as sbvr-types can be a lot smarter in how it handles it in general), and once it's moved then sbvr-types can handle passing the default value through the relevant validate function in order to transform it into the db-specific format

-> table
}

Expand Down
10 changes: 9 additions & 1 deletion test/sbvr-helper.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ createdAtField =
index: null
references: null
defaultValue: 'CURRENT_TIMESTAMP'
sysPeriodField =
dataType: 'Date Time Range'
fieldName: 'sys period'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "sys period" mean?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means system period. It is a range showing when a record is valid from-to. The temporal extension's convention it to call it "sys period" that's why I named it that way.

required: true
index: null
references: null
defaultValue: 'tstzrange(CURRENT_TIMESTAMP, null)'
exports.TableSpace = ->
tables = {}

Expand Down Expand Up @@ -76,7 +83,7 @@ exports.TableSpace = ->
currentTable = this

idField = 'id'
fields = [createdAtField]
fields = [createdAtField, sysPeriodField]
indexes = []
switch lf[0]
when 'Term'
Expand Down Expand Up @@ -173,6 +180,7 @@ exports.TableSpace = ->
referenceScheme: typeName
fields: [
createdAtField
sysPeriodField
primitiveField
]
else
Expand Down
2 changes: 1 addition & 1 deletion test/students.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down