@@ -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
@@ -548,7 +550,7 @@ const createAttribute = (databaseId, collectionId, attribute) => {
548550 return databasesCreateRelationshipAttribute ( {
549551 databaseId,
550552 collectionId,
551- relatedCollectionId : attribute . relatedCollection ,
553+ relatedCollectionId : attribute . relatedTable ?? attribute . relatedCollection ,
552554 type : attribute . relationType ,
553555 twoWay : attribute . twoWay ,
554556 key : attribute . key ,
@@ -667,7 +669,7 @@ const updateAttribute = (databaseId, collectionId, attribute) => {
667669 return databasesUpdateRelationshipAttribute ( {
668670 databaseId,
669671 collectionId,
670- relatedCollectionId : attribute . relatedCollection ,
672+ relatedCollectionId : attribute . relatedTable ?? attribute . relatedCollection ,
671673 type : attribute . relationType ,
672674 twoWay : attribute . twoWay ,
673675 key : attribute . key ,
@@ -881,7 +883,7 @@ const createIndexes = async (indexes, collection) => {
881883 collectionId : collection [ '$id' ] ,
882884 key : index . key ,
883885 type : index . type ,
884- attributes : index . attributes ,
886+ attributes : index . columns ?? index . attributes ,
885887 orders : index . orders ,
886888 parseOutput : false
887889 } ) ;
@@ -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