diff --git a/app/resources.cue b/app/resources.cue index 92be0cd43..62a270221 100644 --- a/app/resources.cue +++ b/app/resources.cue @@ -42,7 +42,7 @@ resources: { [key=_]: {"handle": key, "component": "system", "platform": "cortez } access: { goType: "types.Access" - dal: { type: "Number" } + dal: { type: "Number", meta: { "rdbms:type": "integer" } } } } @@ -271,7 +271,7 @@ resources: { [key=_]: {"handle": key, "component": "system", "platform": "cortez } severity: { goType: "types.Severity" - dal: { type: "Number", default: 0 } + dal: { type: "Number", default: 0, meta: { "rdbms:type": "integer" } } } description: { dal: {} @@ -351,7 +351,7 @@ resources: { [key=_]: {"handle": key, "component": "system", "platform": "cortez goType: "uint64", ident: "resourceID", storeIdent: "rel_resource" - dal: { type: "Number" } + dal: { type: "ID" } } meta: { goType: "rawJson" diff --git a/automation/model/models.gen.go b/automation/model/models.gen.go index fd9236c25..d14a95b22 100644 --- a/automation/model/models.gen.go +++ b/automation/model/models.gen.go @@ -37,7 +37,7 @@ var Session = &dal.Model{ Ident: "Status", Sortable: true, Type: &dal.TypeNumber{HasDefault: true, DefaultValue: 0, - Precision: -1, Scale: -1, + Precision: -1, Scale: -1, Meta: map[string]interface{}{"rdbms:type": "integer"}, }, Store: &dal.CodecAlias{Ident: "status"}, }, @@ -408,7 +408,7 @@ var Workflow = &dal.Model{ Ident: "KeepSessions", Type: &dal.TypeNumber{HasDefault: true, DefaultValue: 0, - Precision: -1, Scale: -1, + Precision: -1, Scale: -1, Meta: map[string]interface{}{"rdbms:type": "integer"}, }, Store: &dal.CodecAlias{Ident: "keep_sessions"}, }, diff --git a/automation/session.cue b/automation/session.cue index 32c6f6ab6..00da88f31 100644 --- a/automation/session.cue +++ b/automation/session.cue @@ -23,7 +23,7 @@ session: { status: { sortable: true, goType: "types.SessionStatus" - dal: { type: "Number", default: 0 } + dal: { type: "Number", default: 0, meta: { "rdbms:type": "integer" } } } event_type: { sortable: true, diff --git a/automation/workflow.cue b/automation/workflow.cue index 50d452234..eecae4ea7 100644 --- a/automation/workflow.cue +++ b/automation/workflow.cue @@ -25,7 +25,7 @@ workflow: { } keep_sessions: { goType: "int" - dal: { type: "Number", default: 0 } + dal: { type: "Number", default: 0, meta: { "rdbms:type": "integer" } } } scope: { goType: "*expr.Vars" diff --git a/codegen/assets/templates/gocode/dal/$component_model.go.tpl b/codegen/assets/templates/gocode/dal/$component_model.go.tpl index a084ab325..578fe6e00 100644 --- a/codegen/assets/templates/gocode/dal/$component_model.go.tpl +++ b/codegen/assets/templates/gocode/dal/$component_model.go.tpl @@ -38,6 +38,7 @@ var {{ .var }} = &dal.Model{ {{- if .dal.precision }} Precision: {{ .dal.precision }}, {{ end }} {{- if .dal.scale }} Scale: {{ .dal.scale }}, {{ end }} {{- if .dal.length }} Length: {{ .dal.length }}, {{ end }} + {{- if .dal.meta }} Meta: {{ printf "%#v" .dal.meta }}, {{ end }} {{- if eq .dal.type "Ref" }} RefAttribute: {{ printf "%q" .dal.attribute }}, RefModel: &dal.ModelRef{ diff --git a/codegen/schema/model.cue b/codegen/schema/model.cue index d99af55ee..7f83e5261 100644 --- a/codegen/schema/model.cue +++ b/codegen/schema/model.cue @@ -65,7 +65,6 @@ import ( nullable: bool | *false - if type == "ID" { generatedByStore: bool | *false default?: 0 @@ -97,6 +96,7 @@ import ( precision: number | *(-1) scale: number | *(-1) default?: number + meta?: { [string]: _ } } if type == "Text" { diff --git a/codegen/server.dal_models.cue b/codegen/server.dal_models.cue index 02fda4dae..397b25125 100644 --- a/codegen/server.dal_models.cue +++ b/codegen/server.dal_models.cue @@ -29,6 +29,10 @@ _dalModelFn: { if attr.dal.default != _|_ { "quotedDefault": attr.dal.type == "String" } + + if attr.dal.meta != _|_ { + "meta": attr.dal.meta + } } } ] diff --git a/compose/model/models.gen.go b/compose/model/models.gen.go index 23c2c4dc0..ca5383cb1 100644 --- a/compose/model/models.gen.go +++ b/compose/model/models.gen.go @@ -358,7 +358,7 @@ var ModuleField = &dal.Model{ &dal.Attribute{ Ident: "Place", Sortable: true, - Type: &dal.TypeNumber{Precision: -1, Scale: -1}, + Type: &dal.TypeNumber{Precision: -1, Scale: -1, Meta: map[string]interface{}{"rdbms:type": "integer"}}, Store: &dal.CodecAlias{Ident: "place"}, }, @@ -656,7 +656,7 @@ var Page = &dal.Model{ Ident: "Weight", Sortable: true, Type: &dal.TypeNumber{HasDefault: true, DefaultValue: 0, - Precision: -1, Scale: -1, + Precision: -1, Scale: -1, Meta: map[string]interface{}{"rdbms:type": "integer"}, }, Store: &dal.CodecAlias{Ident: "weight"}, }, @@ -765,7 +765,7 @@ var Record = &dal.Model{ &dal.Attribute{ Ident: "Revision", - Type: &dal.TypeNumber{Precision: -1, Scale: -1}, + Type: &dal.TypeNumber{Precision: -1, Scale: -1, Meta: map[string]interface{}{"rdbms:type": "integer"}}, Store: &dal.CodecAlias{Ident: "revision"}, }, diff --git a/compose/module_field.cue b/compose/module_field.cue index e4dce5247..c5ecd4820 100644 --- a/compose/module_field.cue +++ b/compose/module_field.cue @@ -23,7 +23,7 @@ moduleField: { place: { sortable: true, goType: "int" - dal: { type: "Number" } + dal: { type: "Number", meta: { "rdbms:type": "integer" } } } kind: { sortable: true, diff --git a/compose/page.cue b/compose/page.cue index 1525f44de..5f330a990 100644 --- a/compose/page.cue +++ b/compose/page.cue @@ -55,7 +55,7 @@ page: { } weight: { goType: "int", sortable: true - dal: { type: "Number", default: 0 } + dal: { type: "Number", default: 0, meta: { "rdbms:type": "integer" } } } description: { goType: "string" diff --git a/compose/record.cue b/compose/record.cue index 99798bdef..b8ff0a6da 100644 --- a/compose/record.cue +++ b/compose/record.cue @@ -17,7 +17,7 @@ record: { id: schema.IdField revision: { goType: "uint" - dal: { type: "Number" } + dal: { type: "Number", meta: { "rdbms:type": "integer" } } } module_id: { ident: "moduleID", diff --git a/compose/record_revision.cue b/compose/record_revision.cue index 43703e583..f294483d2 100644 --- a/compose/record_revision.cue +++ b/compose/record_revision.cue @@ -18,7 +18,7 @@ record_revision: { } revision: { goType: "uint" - dal: { type: "Number" } + dal: { type: "Number", meta: { "rdbms:type": "integer" } } } operation: { dal: {} diff --git a/pkg/dal/attribute_types.go b/pkg/dal/attribute_types.go index 9b6407d70..951650080 100644 --- a/pkg/dal/attribute_types.go +++ b/pkg/dal/attribute_types.go @@ -91,6 +91,7 @@ type ( HasDefault bool DefaultValue float64 + Meta map[string]any } // TypeText handles string coding @@ -151,9 +152,10 @@ type ( } TypeUUID struct { - // Nullable bool } + + TypeNumberStoreNativeType string ) const ( diff --git a/store/adapters/rdbms/drivers/postgres/dialect.go b/store/adapters/rdbms/drivers/postgres/dialect.go index 9e1e440d7..0806f24c1 100644 --- a/store/adapters/rdbms/drivers/postgres/dialect.go +++ b/store/adapters/rdbms/drivers/postgres/dialect.go @@ -9,6 +9,7 @@ import ( "github.com/doug-martin/goqu/v9" "github.com/doug-martin/goqu/v9/dialect/postgres" "github.com/doug-martin/goqu/v9/exp" + "github.com/spf13/cast" ) type ( @@ -143,6 +144,12 @@ func (postgresDialect) AttributeToColumn(attr *dal.Attribute) (col *ddl.Column, col.Default = ddl.DefaultValueCurrentTimestamp(t.DefaultCurrentTimestamp) case *dal.TypeNumber: + if numType := cast.ToString(t.Meta["rdbms:type"]); numType != "" { + col.Type.Name = numType + col.Default = ddl.DefaultNumber(t.HasDefault, 0, t.DefaultValue) + break + } + col.Type.Name = "NUMERIC" switch { diff --git a/system/apigw_filter.cue b/system/apigw_filter.cue index 5185c1faf..839072d0b 100644 --- a/system/apigw_filter.cue +++ b/system/apigw_filter.cue @@ -16,8 +16,10 @@ apigw_filter: { sortable: true, goType: "uint64", storeIdent: "rel_route" dal: { type: "Ref", refModelResType: "corteza::system:apigw-route" } } - weight: { sortable: true, goType: "uint64" - dal: { type: "Number" } + weight: { + sortable: true, + goType: "uint64" + dal: { type: "Number", meta: { "rdbms:type": "integer" } } } kind: { sortable: true diff --git a/system/application.cue b/system/application.cue index 4138e37e0..ab9a10c3d 100644 --- a/system/application.cue +++ b/system/application.cue @@ -20,7 +20,7 @@ application: { weight: { goType: "int", sortable: true - dal: { type: "Number", default: 0 } + dal: { type: "Number", default: 0, meta: { "rdbms:type": "integer" } } } unify: { goType: "*types.ApplicationUnify" diff --git a/system/dal_sensitivity_level.cue b/system/dal_sensitivity_level.cue index 1892f7c38..7893e0abf 100644 --- a/system/dal_sensitivity_level.cue +++ b/system/dal_sensitivity_level.cue @@ -10,8 +10,9 @@ dal_sensitivity_level: { id: schema.IdField handle: schema.HandleField level: { - sortable: true, goType: "int" - dal: { type: "Number" } + sortable: true, + goType: "int" + dal: { type: "Number", meta: { "rdbms:type": "integer" } } } meta: { diff --git a/system/model/corteza.gen.go b/system/model/corteza.gen.go index b86843ede..bac6f774e 100644 --- a/system/model/corteza.gen.go +++ b/system/model/corteza.gen.go @@ -83,7 +83,7 @@ var Action = &dal.Model{ Ident: "Severity", Type: &dal.TypeNumber{HasDefault: true, DefaultValue: 0, - Precision: -1, Scale: -1, + Precision: -1, Scale: -1, Meta: map[string]interface{}{"rdbms:type": "integer"}, }, Store: &dal.CodecAlias{Ident: "severity"}, }, @@ -315,7 +315,7 @@ var ResourceActivity = &dal.Model{ &dal.Attribute{ Ident: "ResourceID", - Type: &dal.TypeNumber{Precision: -1, Scale: -1}, + Type: &dal.TypeID{}, Store: &dal.CodecAlias{Ident: "rel_resource"}, }, @@ -383,7 +383,7 @@ var Rule = &dal.Model{ &dal.Attribute{ Ident: "Access", - Type: &dal.TypeNumber{Precision: -1, Scale: -1}, + Type: &dal.TypeNumber{Precision: -1, Scale: -1, Meta: map[string]interface{}{"rdbms:type": "integer"}}, Store: &dal.CodecAlias{Ident: "access"}, }, }, diff --git a/system/model/models.gen.go b/system/model/models.gen.go index 499361bc0..a82d0f314 100644 --- a/system/model/models.gen.go +++ b/system/model/models.gen.go @@ -35,7 +35,7 @@ var ApigwFilter = &dal.Model{ &dal.Attribute{ Ident: "Weight", Sortable: true, - Type: &dal.TypeNumber{Precision: -1, Scale: -1}, + Type: &dal.TypeNumber{Precision: -1, Scale: -1, Meta: map[string]interface{}{"rdbms:type": "integer"}}, Store: &dal.CodecAlias{Ident: "weight"}, }, @@ -290,7 +290,7 @@ var Application = &dal.Model{ Ident: "Weight", Sortable: true, Type: &dal.TypeNumber{HasDefault: true, DefaultValue: 0, - Precision: -1, Scale: -1, + Precision: -1, Scale: -1, Meta: map[string]interface{}{"rdbms:type": "integer"}, }, Store: &dal.CodecAlias{Ident: "weight"}, }, @@ -1136,7 +1136,7 @@ var DalSensitivityLevel = &dal.Model{ &dal.Attribute{ Ident: "Level", Sortable: true, - Type: &dal.TypeNumber{Precision: -1, Scale: -1}, + Type: &dal.TypeNumber{Precision: -1, Scale: -1, Meta: map[string]interface{}{"rdbms:type": "integer"}}, Store: &dal.CodecAlias{Ident: "level"}, }, @@ -1643,7 +1643,7 @@ var Reminder = &dal.Model{ &dal.Attribute{ Ident: "SnoozeCount", - Type: &dal.TypeNumber{Precision: -1, Scale: -1}, + Type: &dal.TypeNumber{Precision: -1, Scale: -1, Meta: map[string]interface{}{"rdbms:type": "integer"}}, Store: &dal.CodecAlias{Ident: "snooze_count"}, }, diff --git a/system/reminder.cue b/system/reminder.cue index bf57fdae8..7ecaab3ea 100644 --- a/system/reminder.cue +++ b/system/reminder.cue @@ -22,7 +22,7 @@ reminder: { } snooze_count: { goType: "uint" - dal: { type: "Number" } + dal: { type: "Number", meta: { "rdbms:type": "integer" } } } assigned_to: schema.AttributeUserRef assigned_by: schema.AttributeUserRef