@dbml/core 3.14.0 → 3.15.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/lib/export/DbmlExporter.js +38 -1
  2. package/lib/export/MysqlExporter.js +36 -1
  3. package/lib/export/OracleExporter.js +44 -5
  4. package/lib/export/PostgresExporter.js +36 -1
  5. package/lib/export/SqlServerExporter.js +36 -1
  6. package/lib/model_structure/constraint.js +86 -0
  7. package/lib/model_structure/database.js +1 -0
  8. package/lib/model_structure/dbState.js +1 -0
  9. package/lib/model_structure/field.js +23 -1
  10. package/lib/model_structure/table.js +51 -17
  11. package/lib/model_structure/tablePartial.js +3 -0
  12. package/lib/parse/ANTLR/ASTGeneration/AST.js +18 -6
  13. package/lib/parse/ANTLR/ASTGeneration/constants.js +2 -1
  14. package/lib/parse/ANTLR/ASTGeneration/mssql/MssqlASTGen.js +76 -19
  15. package/lib/parse/ANTLR/ASTGeneration/mysql/MySQLASTGen.js +73 -19
  16. package/lib/parse/ANTLR/ASTGeneration/postgres/PostgresASTGen.js +50 -16
  17. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.g4 +1 -1
  18. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.interp +1 -1
  19. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.js +2 -2
  20. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParser.tokens +1314 -1314
  21. package/lib/parse/ANTLR/parsers/postgresql/PostgreSQLParserVisitor.js +1 -1
  22. package/lib/parse/schemarb/parser.pegjs +41 -0
  23. package/lib/parse/schemarbParser.js +568 -226
  24. package/package.json +3 -3
  25. package/types/model_structure/constraint.d.ts +52 -0
  26. package/types/model_structure/database.d.ts +2 -0
  27. package/types/model_structure/field.d.ts +7 -1
  28. package/types/model_structure/table.d.ts +8 -1
  29. package/types/model_structure/tablePartial.d.ts +4 -1
@@ -11,6 +11,7 @@ var _field = _interopRequireDefault(require("./field"));
11
11
  var _indexes = _interopRequireDefault(require("./indexes"));
12
12
  var _config = require("./config");
13
13
  var _utils = require("./utils");
14
+ var _constraint = _interopRequireDefault(require("./constraint"));
14
15
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
15
16
  function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
16
17
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -44,6 +45,8 @@ var Table = /*#__PURE__*/function (_Element) {
44
45
  fields = _ref$fields === void 0 ? [] : _ref$fields,
45
46
  _ref$indexes = _ref.indexes,
46
47
  indexes = _ref$indexes === void 0 ? [] : _ref$indexes,
48
+ _ref$constraints = _ref.constraints,
49
+ constraints = _ref$constraints === void 0 ? [] : _ref$constraints,
47
50
  _ref$schema = _ref.schema,
48
51
  schema = _ref$schema === void 0 ? {} : _ref$schema,
49
52
  token = _ref.token,
@@ -61,6 +64,7 @@ var Table = /*#__PURE__*/function (_Element) {
61
64
  _this.headerColor = headerColor;
62
65
  _this.fields = [];
63
66
  _this.indexes = [];
67
+ _this.constraints = [];
64
68
  _this.schema = schema;
65
69
  _this.partials = partials;
66
70
  _this.dbState = _this.schema.dbState;
@@ -71,6 +75,7 @@ var Table = /*#__PURE__*/function (_Element) {
71
75
  _this.processPartials();
72
76
  _this.checkFieldCount();
73
77
  _this.processIndexes(indexes);
78
+ _this.processConstraints(constraints);
74
79
  return _this;
75
80
  }
76
81
  _inherits(Table, _Element);
@@ -137,6 +142,21 @@ var Table = /*#__PURE__*/function (_Element) {
137
142
  }
138
143
  });
139
144
  }
145
+ }, {
146
+ key: "processConstraints",
147
+ value: function processConstraints(constraints) {
148
+ var _this5 = this;
149
+ constraints.forEach(function (constraint) {
150
+ _this5.pushConstraint(new _constraint["default"](_objectSpread(_objectSpread({}, constraint), {}, {
151
+ table: _this5
152
+ })));
153
+ });
154
+ }
155
+ }, {
156
+ key: "pushConstraint",
157
+ value: function pushConstraint(constraint) {
158
+ this.constraints.push(constraint);
159
+ }
140
160
  }, {
141
161
  key: "findField",
142
162
  value: function findField(fieldName) {
@@ -153,7 +173,7 @@ var Table = /*#__PURE__*/function (_Element) {
153
173
  key: "processPartials",
154
174
  value: function processPartials() {
155
175
  var _this$partials,
156
- _this5 = this;
176
+ _this6 = this;
157
177
  if (!((_this$partials = this.partials) !== null && _this$partials !== void 0 && _this$partials.length)) return;
158
178
  /**
159
179
  * When encountering conflicting columns or settings with identical names, the following resolution order is applied:
@@ -182,14 +202,14 @@ var Table = /*#__PURE__*/function (_Element) {
182
202
 
183
203
  // insert placeholder into table.fields
184
204
  sortedPartials.toReversed().forEach(function (partial) {
185
- _this5.fields.splice(partial.order, 0, 'dummy');
205
+ _this6.fields.splice(partial.order, 0, 'dummy');
186
206
  });
187
207
  sortedPartials.forEach(function (partial) {
188
- var tablePartial = _this5.schema.database.findTablePartial(partial.name);
189
- if (!tablePartial) _this5.error("Table partial ".concat(partial.name, " not found"), partial.token);
208
+ var tablePartial = _this6.schema.database.findTablePartial(partial.name);
209
+ if (!tablePartial) _this6.error("Table partial ".concat(partial.name, " not found"), partial.token);
190
210
  partial.id = tablePartial.id;
191
211
  if (tablePartial.fields) {
192
- var _this5$fields;
212
+ var _this6$fields;
193
213
  // ignore fields that already exist in the table, or have been added by a later partial
194
214
  var rawFields = tablePartial.fields.filter(function (f) {
195
215
  return !existingFieldNames.has(f.name);
@@ -200,12 +220,12 @@ var Table = /*#__PURE__*/function (_Element) {
200
220
  // convert inline_refs from injected fields to refs
201
221
  if (rawField.inline_refs) {
202
222
  rawField.inline_refs.forEach(function (iref) {
203
- var _this5$schema;
223
+ var _this6$schema;
204
224
  var ref = {
205
225
  token: rawField.token,
206
226
  endpoints: [{
207
- tableName: _this5.name,
208
- schemaName: (_this5$schema = _this5.schema) === null || _this5$schema === void 0 ? void 0 : _this5$schema.name,
227
+ tableName: _this6.name,
228
+ schemaName: (_this6$schema = _this6.schema) === null || _this6$schema === void 0 ? void 0 : _this6$schema.name,
209
229
  fieldNames: [rawField.name],
210
230
  relation: ['-', '<'].includes(iref.relation) ? '1' : '*',
211
231
  token: rawField.token
@@ -219,36 +239,44 @@ var Table = /*#__PURE__*/function (_Element) {
219
239
  injectedPartial: tablePartial
220
240
  };
221
241
  // The global array containing references with 1 endpoint being a field injected from a partial to a table
222
- _this5.schema.database.injectedRawRefs.push(ref);
242
+ _this6.schema.database.injectedRawRefs.push(ref);
223
243
  });
224
244
  }
225
245
  return new _field["default"](_objectSpread(_objectSpread({}, rawField), {}, {
226
246
  noteToken: null,
227
- table: _this5,
247
+ table: _this6,
228
248
  injectedPartial: tablePartial,
229
249
  injectedToken: partial.token
230
250
  }));
231
251
  });
232
- (_this5$fields = _this5.fields).splice.apply(_this5$fields, [partial.order, 1].concat(_toConsumableArray(fields)));
252
+ (_this6$fields = _this6.fields).splice.apply(_this6$fields, [partial.order, 1].concat(_toConsumableArray(fields)));
233
253
  } else {
234
- _this5.fields.splice(partial.order, 1); // still need to remove the dummy element, even when there's no field in the partial
254
+ _this6.fields.splice(partial.order, 1); // still need to remove the dummy element, even when there's no field in the partial
235
255
  }
236
256
 
237
257
  // merge settings
238
258
  if (!existingSettingNames.has('note') && !(0, _lodash.isNil)(tablePartial.note)) {
239
- _this5.noteToken = null;
240
- _this5.note = tablePartial.note;
259
+ _this6.noteToken = null;
260
+ _this6.note = tablePartial.note;
241
261
  existingSettingNames.add('note');
242
262
  }
243
263
  if (!existingSettingNames.has('headerColor') && !(0, _lodash.isNil)(tablePartial.headerColor)) {
244
- _this5.headerColor = tablePartial.headerColor;
264
+ _this6.headerColor = tablePartial.headerColor;
245
265
  existingSettingNames.add('headerColor');
246
266
  }
247
267
 
248
268
  // merge indexes
249
269
  tablePartial.indexes.forEach(function (index) {
250
- _this5.indexes.push(new _indexes["default"](_objectSpread(_objectSpread({}, index), {}, {
251
- table: _this5,
270
+ _this6.indexes.push(new _indexes["default"](_objectSpread(_objectSpread({}, index), {}, {
271
+ table: _this6,
272
+ injectedPartial: tablePartial
273
+ })));
274
+ });
275
+ tablePartial.constraints.forEach(function (constraint) {
276
+ _this6.constraints.push(new _constraint["default"](_objectSpread(_objectSpread({}, constraint), {}, {
277
+ name: constraint.name && "".concat(_this6.name, ".").concat(constraint.name),
278
+ // deduplicate constraint names when instantiated to tables
279
+ table: _this6,
252
280
  injectedPartial: tablePartial
253
281
  })));
254
282
  });
@@ -280,6 +308,9 @@ var Table = /*#__PURE__*/function (_Element) {
280
308
  }),
281
309
  indexIds: this.indexes.map(function (i) {
282
310
  return i.id;
311
+ }),
312
+ constraintIds: this.constraints.map(function (c) {
313
+ return c.id;
283
314
  })
284
315
  };
285
316
  }
@@ -314,6 +345,9 @@ var Table = /*#__PURE__*/function (_Element) {
314
345
  this.indexes.forEach(function (index) {
315
346
  return index.normalize(model);
316
347
  });
348
+ this.constraints.forEach(function (constraint) {
349
+ return constraint.normalize(model);
350
+ });
317
351
  }
318
352
  }]);
319
353
  }(_element["default"]);
@@ -33,6 +33,8 @@ var TablePartial = /*#__PURE__*/function (_Element) {
33
33
  fields = _ref$fields === void 0 ? [] : _ref$fields,
34
34
  _ref$indexes = _ref.indexes,
35
35
  indexes = _ref$indexes === void 0 ? [] : _ref$indexes,
36
+ _ref$constraints = _ref.constraints,
37
+ constraints = _ref$constraints === void 0 ? [] : _ref$constraints,
36
38
  token = _ref.token,
37
39
  headerColor = _ref.headerColor,
38
40
  _ref$noteToken = _ref.noteToken,
@@ -46,6 +48,7 @@ var TablePartial = /*#__PURE__*/function (_Element) {
46
48
  _this.headerColor = headerColor;
47
49
  _this.fields = fields;
48
50
  _this.indexes = indexes;
51
+ _this.constraints = constraints;
49
52
  _this.dbState = dbState;
50
53
  _this.generateId();
51
54
  return _this;
@@ -70,7 +70,8 @@ var Field = exports.Field = /*#__PURE__*/function () {
70
70
  * dbdefault: {value: string, type: 'string' | 'number' | 'boolean' | 'expression'},
71
71
  * unique: boolean,
72
72
  * pk: boolean,
73
- * note: {value: string}
73
+ * note: {value: string},
74
+ * constraints: {expression: string, name?: string}[]
74
75
  * }} param0
75
76
  */
76
77
  function Field(_ref2) {
@@ -81,7 +82,8 @@ var Field = exports.Field = /*#__PURE__*/function () {
81
82
  dbdefault = _ref2.dbdefault,
82
83
  unique = _ref2.unique,
83
84
  pk = _ref2.pk,
84
- note = _ref2.note;
85
+ note = _ref2.note,
86
+ constraints = _ref2.constraints;
85
87
  _classCallCheck(this, Field);
86
88
  /** @type {string} */
87
89
  this.name = name;
@@ -106,6 +108,9 @@ var Field = exports.Field = /*#__PURE__*/function () {
106
108
 
107
109
  /** @type {{value: string}} */
108
110
  this.note = note;
111
+
112
+ /** @type {{expression: string, name?: string}[]} */
113
+ this.constraints = constraints;
109
114
  }
110
115
  return _createClass(Field, [{
111
116
  key: "toJSON",
@@ -118,7 +123,8 @@ var Field = exports.Field = /*#__PURE__*/function () {
118
123
  dbdefault: this.dbdefault,
119
124
  unique: this.unique,
120
125
  pk: this.pk,
121
- note: this.note
126
+ note: this.note,
127
+ constraints: this.constraints
122
128
  };
123
129
  }
124
130
  }]);
@@ -130,7 +136,8 @@ var Table = exports.Table = /*#__PURE__*/function () {
130
136
  * schemaName: string,
131
137
  * fields: Field[],
132
138
  * indexes: Index[],
133
- * note: {value: string}
139
+ * note: {value: string},
140
+ * constraints: {expression: string, name?: string}[]
134
141
  * }} param0
135
142
  */
136
143
  function Table(_ref3) {
@@ -138,7 +145,8 @@ var Table = exports.Table = /*#__PURE__*/function () {
138
145
  schemaName = _ref3.schemaName,
139
146
  fields = _ref3.fields,
140
147
  indexes = _ref3.indexes,
141
- note = _ref3.note;
148
+ note = _ref3.note,
149
+ constraints = _ref3.constraints;
142
150
  _classCallCheck(this, Table);
143
151
  /** @type {string} */
144
152
  this.name = name;
@@ -154,6 +162,9 @@ var Table = exports.Table = /*#__PURE__*/function () {
154
162
 
155
163
  /** @type {{value: string}} */
156
164
  this.note = note;
165
+
166
+ /** @type {{expression: string, name?: string}[]} */
167
+ this.constraints = constraints || [];
157
168
  }
158
169
  return _createClass(Table, [{
159
170
  key: "toJSON",
@@ -168,7 +179,8 @@ var Table = exports.Table = /*#__PURE__*/function () {
168
179
  indexes: (_this$indexes = this.indexes) === null || _this$indexes === void 0 ? void 0 : _this$indexes.map(function (i) {
169
180
  return i.toJSON();
170
181
  }),
171
- note: this.note
182
+ note: this.note,
183
+ constraints: this.constraints
172
184
  };
173
185
  }
174
186
  }]);
@@ -10,7 +10,8 @@ var TABLE_CONSTRAINT_KIND = exports.TABLE_CONSTRAINT_KIND = {
10
10
  FK: 'fk',
11
11
  UNIQUE: 'unique',
12
12
  PK: 'pk',
13
- DEFAULT: 'default'
13
+ DEFAULT: 'default',
14
+ CHECK: 'check'
14
15
  };
15
16
  var COLUMN_CONSTRAINT_KIND = exports.COLUMN_CONSTRAINT_KIND = {
16
17
  NOT_NULL: 'not_null',
@@ -11,6 +11,9 @@ var _constants = require("../constants");
11
11
  var _helpers = require("../helpers");
12
12
  var _AST = require("../AST");
13
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
14
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
15
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
16
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
14
17
  function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
15
18
  function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
16
19
  function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
@@ -113,17 +116,17 @@ var parseFieldsAndInlineRefsFromFieldsData = function parseFieldsAndInlineRefsFr
113
116
  });
114
117
  acc[0].push(inlineRefs);
115
118
  acc[1].push(fieldData.field);
116
- (_acc$ = acc[2]).push.apply(_acc$, _toConsumableArray(fieldData.checkConstraints));
119
+ (_acc$ = acc[2]).push.apply(_acc$, _toConsumableArray(fieldData.enumCheckConstraints));
117
120
  return acc;
118
121
  }, [[], [], []]),
119
122
  _fieldsData$reduce2 = _slicedToArray(_fieldsData$reduce, 3),
120
123
  resInlineRefs = _fieldsData$reduce2[0],
121
124
  fields = _fieldsData$reduce2[1],
122
- checkConstraints = _fieldsData$reduce2[2];
125
+ enumCheckConstraints = _fieldsData$reduce2[2];
123
126
  return {
124
127
  inlineRefs: resInlineRefs,
125
128
  fields: fields,
126
- checkConstraints: checkConstraints
129
+ enumCheckConstraints: enumCheckConstraints
127
130
  };
128
131
  };
129
132
  var MssqlASTGen = exports["default"] = /*#__PURE__*/function (_TSqlParserVisitor) {
@@ -603,17 +606,26 @@ var MssqlASTGen = exports["default"] = /*#__PURE__*/function (_TSqlParserVisitor
603
606
  var _parseFieldsAndInline = parseFieldsAndInlineRefsFromFieldsData(fieldsData, tableName, schemaName),
604
607
  inlineRefs = _parseFieldsAndInline.inlineRefs,
605
608
  fields = _parseFieldsAndInline.fields,
606
- columnCheckConstraints = _parseFieldsAndInline.checkConstraints;
609
+ columnEnumCheckConstraints = _parseFieldsAndInline.enumCheckConstraints;
607
610
  (_this$data$refs = this.data.refs).push.apply(_this$data$refs, _toConsumableArray((0, _lodash.flatten)(inlineRefs)));
608
611
  (_this$data$refs2 = this.data.refs).push.apply(_this$data$refs2, _toConsumableArray(tableRefs.map(function (tableRef) {
609
612
  tableRef.endpoints[0].tableName = tableName;
610
613
  tableRef.endpoints[0].schemaName = schemaName;
611
614
  return tableRef;
612
615
  })));
613
-
614
- // these check constraints represent enums
615
- var checkConstraints = columnCheckConstraints.concat(tableCheckConstraints);
616
- checkConstraints.forEach(function (checkConstraint) {
616
+ var allCheckConstraints = columnEnumCheckConstraints.concat(tableCheckConstraints);
617
+ var rawTableConstraints = [];
618
+ allCheckConstraints.forEach(function (checkConstraint) {
619
+ if (checkConstraint.isRaw) {
620
+ var constraintObj = {
621
+ expression: checkConstraint.expression
622
+ };
623
+ if (checkConstraint.name) {
624
+ constraintObj.name = checkConstraint.name;
625
+ }
626
+ rawTableConstraints.push(constraintObj);
627
+ return;
628
+ }
617
629
  var field = fields.find(function (fieldItem) {
618
630
  return fieldItem.name === checkConstraint.column;
619
631
  });
@@ -628,7 +640,7 @@ var MssqlASTGen = exports["default"] = /*#__PURE__*/function (_TSqlParserVisitor
628
640
  schemaName: schemaName
629
641
  });
630
642
  _this8.data.enums.push(enumObject);
631
- // TODO: handle multiple enums for the same field
643
+ // TODO: Handle multiple enums for the same field
632
644
  field.type.type_name = enumObject.name;
633
645
  field.type.schemaName = enumObject.schemaName;
634
646
  });
@@ -636,7 +648,8 @@ var MssqlASTGen = exports["default"] = /*#__PURE__*/function (_TSqlParserVisitor
636
648
  name: tableName,
637
649
  schemaName: schemaName,
638
650
  fields: fields,
639
- indexes: tableIndices.concat(indexes)
651
+ indexes: tableIndices.concat(indexes),
652
+ constraints: rawTableConstraints
640
653
  });
641
654
  this.data.tables.push(table);
642
655
  }
@@ -717,7 +730,7 @@ var MssqlASTGen = exports["default"] = /*#__PURE__*/function (_TSqlParserVisitor
717
730
  value: {
718
731
  field: field,
719
732
  inline_refs: [],
720
- checkConstraints: []
733
+ enumCheckConstraints: []
721
734
  }
722
735
  };
723
736
  var columnDefinitions = ctx.column_definition_element().map(function (columnDef) {
@@ -755,11 +768,24 @@ var MssqlASTGen = exports["default"] = /*#__PURE__*/function (_TSqlParserVisitor
755
768
  {
756
769
  var _columnDef$value = columnDef.value,
757
770
  columnDefType = _columnDef$value.type,
758
- value = _columnDef$value.value;
759
-
760
- // we keep the current behavior: when a field has a check constraints cannot be converted to enum, we will ignore it
761
- if (columnDefType !== CHECK_CONSTRAINT_CONDITION_TYPE.ENUM) return;
762
- definition.value.checkConstraints.push(value);
771
+ value = _columnDef$value.value,
772
+ name = _columnDef$value.name;
773
+ if (columnDefType === CHECK_CONSTRAINT_CONDITION_TYPE.ENUM) {
774
+ // If it's an ENUM type (simple IN clause without NOT), queue it for enum extraction
775
+ definition.value.enumCheckConstraints.push(value);
776
+ } else if (columnDefType === CHECK_CONSTRAINT_CONDITION_TYPE.RAW) {
777
+ // For RAW constraints (complex expressions), add directly to field.constraints array
778
+ if (!field.constraints) {
779
+ field.constraints = [];
780
+ }
781
+ var constraintObj = {
782
+ expression: value
783
+ };
784
+ if (name) {
785
+ constraintObj.name = name;
786
+ }
787
+ field.constraints.push(constraintObj);
788
+ }
763
789
  break;
764
790
  }
765
791
  default:
@@ -871,9 +897,13 @@ var MssqlASTGen = exports["default"] = /*#__PURE__*/function (_TSqlParserVisitor
871
897
 
872
898
  // we do not handle check constraint since it is complicated and hard to extract enum from it
873
899
  if (ctx.check_constraint()) {
900
+ var constraintName = ctx.id_() ? ctx.id_().accept(this) : null;
901
+ var checkConstraintResult = ctx.check_constraint().accept(this);
874
902
  return {
875
903
  kind: _constants.COLUMN_CONSTRAINT_KIND.CHECK,
876
- value: ctx.check_constraint().accept(this)
904
+ value: _objectSpread(_objectSpread({}, checkConstraintResult), {}, {
905
+ name: constraintName
906
+ })
877
907
  };
878
908
  }
879
909
  return null;
@@ -1113,10 +1143,23 @@ var MssqlASTGen = exports["default"] = /*#__PURE__*/function (_TSqlParserVisitor
1113
1143
  }
1114
1144
  if (ctx.check_constraint()) {
1115
1145
  var checkConstraint = ctx.check_constraint().accept(this);
1116
- if (checkConstraint.type !== CHECK_CONSTRAINT_CONDITION_TYPE.ENUM) return null;
1146
+
1147
+ // If it's an ENUM type (simple IN clause), return for enum extraction
1148
+ if (checkConstraint.type === CHECK_CONSTRAINT_CONDITION_TYPE.ENUM) {
1149
+ return {
1150
+ kind: _constants.TABLE_CONSTRAINT_KIND.CHECK,
1151
+ value: checkConstraint.value
1152
+ };
1153
+ }
1154
+
1155
+ // For RAW constraints, return them too so they can be added to table.constraints
1117
1156
  return {
1118
1157
  kind: _constants.TABLE_CONSTRAINT_KIND.CHECK,
1119
- value: checkConstraint.value
1158
+ value: {
1159
+ expression: checkConstraint.value,
1160
+ name: name,
1161
+ isRaw: true // Mark as raw constraint
1162
+ }
1120
1163
  };
1121
1164
  }
1122
1165
  return null;
@@ -1221,6 +1264,20 @@ var MssqlASTGen = exports["default"] = /*#__PURE__*/function (_TSqlParserVisitor
1221
1264
  field.dbdefault = columnDefault.defaultValue;
1222
1265
  });
1223
1266
  checkConstraints.forEach(function (checkConstraint) {
1267
+ // Handle RAW table-level constraints (complex expressions that won't become enums)
1268
+ if (checkConstraint.isRaw) {
1269
+ var constraintObj = {
1270
+ expression: checkConstraint.expression
1271
+ };
1272
+ if (checkConstraint.name) {
1273
+ constraintObj.name = checkConstraint.name;
1274
+ }
1275
+ table.constraints.push(constraintObj);
1276
+ return;
1277
+ }
1278
+
1279
+ // Handle ENUM constraints: simple IN clauses like CHECK (status IN ('a', 'b', 'c'))
1280
+ // These get converted to actual Enum objects and the field type is updated
1224
1281
  var field = table.fields.find(function (fieldItem) {
1225
1282
  return fieldItem.name === checkConstraint.column;
1226
1283
  });