@famgia/omnify-atlas 2.0.30 → 2.0.31
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.
- package/dist/index.cjs +22 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +22 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -147,6 +147,20 @@ function propertyToSnapshot(property) {
|
|
|
147
147
|
idType: prop.idType
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
|
+
function toColumnName(propertyName) {
|
|
151
|
+
return propertyName.replace(/([A-Z])/g, "_$1").toLowerCase().replace(/^_/, "");
|
|
152
|
+
}
|
|
153
|
+
function propertyToColumnName(propName, properties) {
|
|
154
|
+
const colName = toColumnName(propName);
|
|
155
|
+
const prop = properties?.[propName];
|
|
156
|
+
if (prop?.type === "Association") {
|
|
157
|
+
const assoc = prop;
|
|
158
|
+
if ((assoc.relation === "ManyToOne" || assoc.relation === "OneToOne") && !assoc.mappedBy) {
|
|
159
|
+
return colName + "_id";
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return colName;
|
|
163
|
+
}
|
|
150
164
|
function schemaToSnapshot(schema, hash, modifiedAt) {
|
|
151
165
|
const properties = {};
|
|
152
166
|
if (schema.properties) {
|
|
@@ -155,17 +169,23 @@ function schemaToSnapshot(schema, hash, modifiedAt) {
|
|
|
155
169
|
}
|
|
156
170
|
}
|
|
157
171
|
const opts = schema.options;
|
|
172
|
+
const propToColName = (propName) => {
|
|
173
|
+
return propertyToColumnName(propName, schema.properties);
|
|
174
|
+
};
|
|
158
175
|
let indexes;
|
|
159
176
|
if (opts?.indexes && opts.indexes.length > 0) {
|
|
160
177
|
indexes = opts.indexes.map((idx) => ({
|
|
161
|
-
columns: idx.columns,
|
|
178
|
+
columns: idx.columns.map(propToColName),
|
|
162
179
|
unique: idx.unique ?? false,
|
|
163
180
|
name: idx.name
|
|
164
181
|
}));
|
|
165
182
|
}
|
|
166
183
|
let uniqueConstraints;
|
|
167
184
|
if (opts?.unique) {
|
|
168
|
-
|
|
185
|
+
const rawConstraints = Array.isArray(opts.unique[0]) ? opts.unique : [opts.unique];
|
|
186
|
+
uniqueConstraints = rawConstraints.map(
|
|
187
|
+
(constraint) => constraint.map(propToColName)
|
|
188
|
+
);
|
|
169
189
|
}
|
|
170
190
|
return {
|
|
171
191
|
name: schema.name,
|