@baclet/cli 0.1.2 → 0.1.3
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/package.json +1 -1
- package/src/commands/project.js +29 -2
package/package.json
CHANGED
package/src/commands/project.js
CHANGED
|
@@ -70,6 +70,32 @@ export async function listProjects() {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
function normalizeModels(models) {
|
|
74
|
+
return models.map((model) => ({
|
|
75
|
+
...model,
|
|
76
|
+
fields: Object.fromEntries(
|
|
77
|
+
Object.entries(model.fields).map(([name, field]) => [
|
|
78
|
+
name,
|
|
79
|
+
{
|
|
80
|
+
type: field.type,
|
|
81
|
+
required: field.required ?? false,
|
|
82
|
+
default: field.default ?? null,
|
|
83
|
+
unique: field.unique ?? false,
|
|
84
|
+
index: field.index ?? false,
|
|
85
|
+
values: field.values ?? [],
|
|
86
|
+
precision: field.precision ?? 0,
|
|
87
|
+
scale: field.scale ?? 0,
|
|
88
|
+
reference: {
|
|
89
|
+
model: field.reference?.model ?? "",
|
|
90
|
+
field: field.reference?.field ?? "",
|
|
91
|
+
onDelete: field.reference?.onDelete ?? "",
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
]),
|
|
95
|
+
),
|
|
96
|
+
}));
|
|
97
|
+
}
|
|
98
|
+
|
|
73
99
|
function printDiff(result) {
|
|
74
100
|
const statements = result?.diff?.statements || [];
|
|
75
101
|
const warnings = result?.diff?.warnings || [];
|
|
@@ -86,13 +112,14 @@ function printDiff(result) {
|
|
|
86
112
|
async function push(args, apply) {
|
|
87
113
|
const creds = await requireCredentials();
|
|
88
114
|
const { models, projectId } = await loadProject();
|
|
115
|
+
const payloadModels = normalizeModels(models);
|
|
89
116
|
console.log(`Loaded ${models.length} model${models.length === 1 ? "" : "s"} from project ${projectId}.`);
|
|
90
117
|
|
|
91
118
|
const result = await request({
|
|
92
119
|
method: "POST",
|
|
93
120
|
path: `/api/v1/cli/schema/${apply ? "push" : "status"}`,
|
|
94
121
|
token: creds.accessToken,
|
|
95
|
-
body: { projectId, models },
|
|
122
|
+
body: { projectId, models: payloadModels, apply: false },
|
|
96
123
|
});
|
|
97
124
|
printDiff(result);
|
|
98
125
|
|
|
@@ -109,7 +136,7 @@ async function push(args, apply) {
|
|
|
109
136
|
method: "POST",
|
|
110
137
|
path: "/api/v1/cli/schema/push",
|
|
111
138
|
token: creds.accessToken,
|
|
112
|
-
body: { projectId, models, apply: true },
|
|
139
|
+
body: { projectId, models: payloadModels, apply: true },
|
|
113
140
|
});
|
|
114
141
|
console.log(`\nSchema applied. Version ${applied.version} saved.`);
|
|
115
142
|
}
|