@@ -50,10 +50,12 @@ const {
5050 databasesUpdateCollection
5151} = require("./databases");
5252const {
53+ tablesDBCreate,
5354 tablesDBGet,
55+ tablesDBUpdate,
56+ tablesDBCreateTable,
5457 tablesDBGetTable,
55- tablesDBUpdateTable,
56- tablesDBCreateTable
58+ tablesDBUpdateTable
5759} = require("./tables-db");
5860const {
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
18411856const pushCollection = async ({ returnOnZero, attempts } = { returnOnZero: false }) => {
0 commit comments