Skip to content

Commit a304270

Browse files
authored
Merge pull request #1201 from appwrite/fix-row-permissions-sync
2 parents d69be8d + 5dadda0 commit a304270

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ const pullTable = async () => {
358358
});
359359
if (fetchResponse["databases"].length <= 0) {
360360
log("No tables found.");
361-
success(`Successfully pulled ${chalk.bold(totalTables)} tables from ${chalk.bold(totalTablesDBs)} tables databases.`);
361+
success(`Successfully pulled ${chalk.bold(totalTables)} tables from ${chalk.bold(totalTablesDBs)} tableDBs.`);
362362
return;
363363
}
364364

@@ -398,7 +398,7 @@ const pullTable = async () => {
398398
}
399399
}
400400

401-
success(`Successfully pulled ${chalk.bold(totalTables)} tables from ${chalk.bold(totalTablesDBs)} tables databases.`);
401+
success(`Successfully pulled ${chalk.bold(totalTables)} tables from ${chalk.bold(totalTablesDBs)} tableDBs.`);
402402
}
403403

404404
const pullBucket = async () => {

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

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ const {
5050
databasesUpdateCollection
5151
} = require("./databases");
5252
const {
53+
tablesDBCreate,
5354
tablesDBGet,
55+
tablesDBUpdate,
56+
tablesDBCreateTable,
5457
tablesDBGetTable,
55-
tablesDBUpdateTable,
56-
tablesDBCreateTable
58+
tablesDBUpdateTable
5759
} = require("./tables-db");
5860
const {
5961
storageGetBucket, storageUpdateBucket, storageCreateBucket
@@ -1730,7 +1732,7 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
17301732

17311733
const databases = Array.from(new Set(tables.map(table => table['databaseId'])));
17321734

1733-
// Parallel db actions
1735+
// Parallel tablesDB actions
17341736
await Promise.all(databases.map(async (databaseId) => {
17351737
const localDatabase = localConfig.getTablesDB(databaseId);
17361738

@@ -1741,7 +1743,7 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
17411743
});
17421744

17431745
if (database.name !== (localDatabase.name ?? databaseId)) {
1744-
await databasesUpdate({
1746+
await tablesDBUpdate({
17451747
databaseId: databaseId,
17461748
name: localDatabase.name ?? databaseId,
17471749
parseOutput: false
@@ -1752,7 +1754,7 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
17521754
} catch (err) {
17531755
log(`Database ${databaseId} not found. Creating it now ...`);
17541756

1755-
await databasesCreate({
1757+
await tablesDBCreate({
17561758
databaseId: databaseId,
17571759
name: localDatabase.name ?? databaseId,
17581760
parseOutput: false,
@@ -1761,10 +1763,12 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
17611763
}));
17621764

17631765

1764-
if (!(await approveChanges(tables, tablesDBGetTable, KeysTable, 'tableId', 'tables', ['columns', 'indexes'], 'databaseId', 'databaseId',))) {
1766+
if (!(await approveChanges(tables, tablesDBGetTable, KeysTable, 'tableId', 'tables', ['columns', 'indexes'], 'databaseId', 'databaseId'))) {
17651767
return;
17661768
}
1767-
// Parallel collection actions
1769+
let tablesChanged = new Set();
1770+
1771+
// Parallel tables actions
17681772
await Promise.all(tables.map(async (table) => {
17691773
try {
17701774
const remoteTable = await tablesDBGetTable({
@@ -1773,15 +1777,23 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
17731777
parseOutput: false,
17741778
});
17751779

1776-
if (remoteTable.name !== table.name) {
1780+
const changes = [];
1781+
if (remoteTable.name !== table.name) changes.push('name');
1782+
if (remoteTable.rowSecurity !== table.rowSecurity) changes.push('rowSecurity');
1783+
if (JSON.stringify(remoteTable['$permissions']) !== JSON.stringify(table['$permissions'])) changes.push('permissions');
1784+
1785+
if (changes.length > 0) {
17771786
await tablesDBUpdateTable({
17781787
databaseId: table['databaseId'],
17791788
tableId: table['$id'],
17801789
name: table.name,
1781-
parseOutput: false
1790+
parseOutput: false,
1791+
rowSecurity: table.rowSecurity,
1792+
permissions: table['$permissions']
17821793
})
17831794

1784-
success(`Updated ${table.name} ( ${table['$id']} ) name`);
1795+
success(`Updated ${table.name} ( ${table['$id']} ) - ${changes.join(', ')}`);
1796+
tablesChanged.add(table['$id']);
17851797
}
17861798
table.remoteVersion = remoteTable;
17871799

@@ -1794,16 +1806,19 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
17941806
databaseId: table['databaseId'],
17951807
tableId: table['$id'],
17961808
name: table.name,
1797-
documentSecurity: table.documentSecurity,
1809+
rowSecurity: table.rowSecurity,
17981810
permissions: table['$permissions'],
17991811
parseOutput: false
18001812
})
1813+
1814+
success(`Created ${table.name} ( ${table['$id']} )`);
1815+
tablesChanged.add(table['$id']);
18011816
} else {
18021817
throw e;
18031818
}
18041819
}
18051820
}))
1806-
let numberOfTables = 0;
1821+
18071822
// Serialize attribute actions
18081823
for (let table of tables) {
18091824
let columns = table.columns;
@@ -1831,11 +1846,11 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
18311846
} catch (e) {
18321847
throw e;
18331848
}
1834-
numberOfTables++;
1849+
tablesChanged.add(table['$id']);
18351850
success(`Successfully pushed ${table.name} ( ${table['$id']} )`);
18361851
}
18371852

1838-
success(`Successfully pushed ${numberOfTables} tables`);
1853+
success(`Successfully pushed ${tablesChanged.size} tables`);
18391854
}
18401855

18411856
const pushCollection = async ({ returnOnZero, attempts } = { returnOnZero: false }) => {

templates/cli/lib/config.js.twig

Lines changed: 1 addition & 1 deletion
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", "columns", "indexes"]);
12+
const KeysTable = new Set(["$id", "$permissions", "databaseId", "name", "enabled", "rowSecurity", "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"]);

0 commit comments

Comments
 (0)