Skip to content

Commit d69c482

Browse files
committed
finish push pull
1 parent 07aaf74 commit d69c482

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

templates/cli/lib/commands/pull.js.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ const pullTable = async () => {
375375
const { tables } = await paginate(gridsListTables, {
376376
databaseId,
377377
parseOutput: false
378-
}, 100, 'collections');
378+
}, 100, 'tables');
379379

380380
for (const table of tables) {
381381
localConfig.addTable({

templates/cli/lib/commands/push.js.twig

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const inquirer = require("inquirer");
66
const JSONbig = require("json-bigint")({ storeAsString: false });
77
const { Command } = require("commander");
88
const ID = require("../id");
9-
const { localConfig, globalConfig, KeysAttributes, KeysFunction, KeysSite, whitelistKeys, KeysTopics, KeysStorage, KeysTeams, KeysCollection } = require("../config");
9+
const { localConfig, globalConfig, KeysAttributes, KeysFunction, KeysSite, whitelistKeys, KeysTopics, KeysStorage, KeysTeams, KeysCollection, KeysTable } = require("../config");
1010
const { Spinner, SPINNER_ARC, SPINNER_DOTS } = require('../spinner');
1111
const { paginate } = require('../paginate');
1212
const { questionsPushBuckets, questionsPushTeams, questionsPushFunctions, questionsPushSites, questionsGetEntrypoint, questionsPushCollections, questionsPushTables, questionPushChanges, questionPushChangesConfirmation, questionsPushMessagingTopics, questionsPushResources } = require("../questions");
@@ -50,7 +50,8 @@ const {
5050
databasesUpdateCollection
5151
} = require("./databases");
5252
const {
53-
gridsGetDatabase
53+
gridsGetDatabase,
54+
gridsGetTable
5455
} = require("./grids");
5556
const {
5657
storageGetBucket, storageUpdateBucket, storageCreateBucket
@@ -1738,13 +1739,13 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
17381739
}));
17391740

17401741

1741-
if (!(await approveChanges(tables, databasesGetTable, KeysTable, 'tableId', 'tables', ['attributes', 'indexes'], 'databaseId', 'databaseId',))) {
1742+
if (!(await approveChanges(tables, gridsGetTable, KeysTable, 'tableId', 'tables', ['columns', 'indexes'], 'databaseId', 'databaseId',))) {
17421743
return;
17431744
}
17441745
// Parallel collection actions
17451746
await Promise.all(tables.map(async (table) => {
17461747
try {
1747-
const remoteTable = await databasesGetTable({
1748+
const remoteTable = await gridsGetTable({
17481749
databaseId: table['databaseId'],
17491750
tableId: table['$id'],
17501751
parseOutput: false,
@@ -1784,14 +1785,14 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
17841785
let numberOfTables = 0;
17851786
// Serialize attribute actions
17861787
for (let table of tables) {
1787-
let attributes = table.attributes;
1788+
let columns = table.columns;
17881789
let indexes = table.indexes;
17891790

17901791
if (table.isExisted) {
1791-
attributes = await attributesToCreate(table.remoteVersion.attributes, table.attributes, table);
1792+
columns = await attributesToCreate(table.remoteVersion.columns, table.columns, table);
17921793
indexes = await attributesToCreate(table.remoteVersion.indexes, table.indexes, table, true);
17931794

1794-
if ((Array.isArray(attributes) && attributes.length <= 0) && (Array.isArray(indexes) && indexes.length <= 0)) {
1795+
if ((Array.isArray(columns) && columns.length <= 0) && (Array.isArray(indexes) && indexes.length <= 0)) {
17951796
continue;
17961797
}
17971798

@@ -1800,7 +1801,7 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
18001801
log(`Pushing table ${table.name} ( ${table['databaseId']} - ${table['$id']} ) attributes`)
18011802

18021803
try {
1803-
await createAttributes(attributes, table)
1804+
await createAttributes(columns, table)
18041805
} catch (e) {
18051806
throw e;
18061807
}
@@ -1881,7 +1882,7 @@ const pushCollection = async ({ returnOnZero, attempts } = { returnOnZero: false
18811882
}));
18821883

18831884

1884-
if (!(await approveChanges(collections, databasesGetCollection, KeysCollection, 'collectionId', 'collections', ['attributes', 'indexes'], 'databaseId', 'databaseId',))) {
1885+
if (!(await approveChanges(collections, databasesGetCollection, KeysCollection, 'collectionId', 'collections', ['columns', 'indexes'], 'databaseId', 'databaseId',))) {
18851886
return;
18861887
}
18871888
// Parallel collection actions

templates/cli/lib/config.js.twig

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const KeysSite = new Set(["path", "$id", "name", "enabled", "logging", "timeout"
99
const KeysFunction = new Set(["path", "$id", "execute", "name", "enabled", "logging", "runtime", "specification", "scopes", "events", "schedule", "timeout", "entrypoint", "commands", "vars"]);
1010
const KeysDatabase = new Set(["$id", "name", "enabled"]);
1111
const KeysCollection = new Set(["$id", "$permissions", "databaseId", "name", "enabled", "documentSecurity", "attributes", "indexes"]);
12-
const KeysTable = new Set(["$id", "$permissions", "databaseId", "name", "enabled", "documentSecurity", "attributes", "indexes"]);
12+
const KeysTable = new Set(["$id", "$permissions", "databaseId", "name", "enabled", "documentSecurity", "columns", "indexes"]);
1313
const KeysStorage = new Set(["$id", "$permissions", "fileSecurity", "name", "enabled", "maximumFileSize", "allowedFileExtensions", "compression", "encryption", "antivirus"]);
1414
const KeysTopics = new Set(["$id", "name", "subscribe"]);
1515
const KeysTeams = new Set(["$id", "name"]);
@@ -40,6 +40,33 @@ const KeysAttributes = new Set([
4040
// Strings
4141
"encrypt",
4242
]);
43+
const KeysColumns = new Set([
44+
"key",
45+
"type",
46+
"required",
47+
"array",
48+
"size",
49+
"default",
50+
// integer and float
51+
"min",
52+
"max",
53+
// email, enum, URL, IP, and datetime
54+
"format",
55+
// enum
56+
"elements",
57+
// relationship
58+
"relatedCollection",
59+
"relationType",
60+
"twoWay",
61+
"twoWayKey",
62+
"onDelete",
63+
"side",
64+
// Indexes
65+
"attributes",
66+
"orders",
67+
// Strings
68+
"encrypt",
69+
]);
4370
const KeyIndexes = new Set(["key", "type", "status", "attributes", "orders"]);
4471

4572
function whitelistKeys(value, keys, nestedKeys = {}) {
@@ -335,7 +362,7 @@ class Local extends Config {
335362

336363
addTable(props) {
337364
props = whitelistKeys(props, KeysTable, {
338-
attributes: KeysAttributes,
365+
columns: KeysColumns,
339366
indexes: KeyIndexes
340367
});
341368

0 commit comments

Comments
 (0)