@@ -50,10 +50,12 @@ const {
50
50
databasesUpdateCollection
51
51
} = require ( "./databases" ) ;
52
52
const {
53
+ tablesDBCreate,
53
54
tablesDBGet,
55
+ tablesDBUpdate,
56
+ tablesDBCreateTable,
54
57
tablesDBGetTable,
55
- tablesDBUpdateTable,
56
- tablesDBCreateTable
58
+ tablesDBUpdateTable
57
59
} = require ( "./tables-db" ) ;
58
60
const {
59
61
storageGetBucket, storageUpdateBucket, storageCreateBucket
@@ -548,7 +550,7 @@ const createAttribute = (databaseId, collectionId, attribute) => {
548
550
return databasesCreateRelationshipAttribute ( {
549
551
databaseId,
550
552
collectionId,
551
- relatedCollectionId : attribute . relatedCollection ,
553
+ relatedCollectionId : attribute . relatedTable ?? attribute . relatedCollection ,
552
554
type : attribute . relationType ,
553
555
twoWay : attribute . twoWay ,
554
556
key : attribute . key ,
@@ -667,7 +669,7 @@ const updateAttribute = (databaseId, collectionId, attribute) => {
667
669
return databasesUpdateRelationshipAttribute ( {
668
670
databaseId,
669
671
collectionId,
670
- relatedCollectionId : attribute . relatedCollection ,
672
+ relatedCollectionId : attribute . relatedTable ?? attribute . relatedCollection ,
671
673
type : attribute . relationType ,
672
674
twoWay : attribute . twoWay ,
673
675
key : attribute . key ,
@@ -881,7 +883,7 @@ const createIndexes = async (indexes, collection) => {
881
883
collectionId : collection [ '$id' ] ,
882
884
key : index . key ,
883
885
type : index . type ,
884
- attributes : index . attributes ,
886
+ attributes : index . columns ?? index . attributes ,
885
887
orders : index . orders ,
886
888
parseOutput : false
887
889
} ) ;
@@ -1730,7 +1732,7 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
1730
1732
1731
1733
const databases = Array . from ( new Set ( tables . map ( table => table [ 'databaseId' ] ) ) ) ;
1732
1734
1733
- // Parallel db actions
1735
+ // Parallel tablesDB actions
1734
1736
await Promise . all ( databases . map ( async ( databaseId ) => {
1735
1737
const localDatabase = localConfig . getTablesDB ( databaseId ) ;
1736
1738
@@ -1741,7 +1743,7 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
1741
1743
} ) ;
1742
1744
1743
1745
if ( database . name !== ( localDatabase . name ?? databaseId ) ) {
1744
- await databasesUpdate ( {
1746
+ await tablesDBUpdate ( {
1745
1747
databaseId : databaseId ,
1746
1748
name : localDatabase . name ?? databaseId ,
1747
1749
parseOutput : false
@@ -1752,7 +1754,7 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
1752
1754
} catch ( err ) {
1753
1755
log ( `Database ${ databaseId } not found. Creating it now ...` ) ;
1754
1756
1755
- await databasesCreate ( {
1757
+ await tablesDBCreate ( {
1756
1758
databaseId : databaseId ,
1757
1759
name : localDatabase . name ?? databaseId ,
1758
1760
parseOutput : false ,
@@ -1761,10 +1763,12 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
1761
1763
} ) ) ;
1762
1764
1763
1765
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' ) ) ) {
1765
1767
return ;
1766
1768
}
1767
- // Parallel collection actions
1769
+ let tablesChanged = new Set ( ) ;
1770
+
1771
+ // Parallel tables actions
1768
1772
await Promise . all ( tables . map ( async ( table ) => {
1769
1773
try {
1770
1774
const remoteTable = await tablesDBGetTable ( {
@@ -1773,15 +1777,23 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
1773
1777
parseOutput : false ,
1774
1778
} ) ;
1775
1779
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 ) {
1777
1786
await tablesDBUpdateTable ( {
1778
1787
databaseId : table [ 'databaseId' ] ,
1779
1788
tableId : table [ '$id' ] ,
1780
1789
name : table . name ,
1781
- parseOutput : false
1790
+ parseOutput : false ,
1791
+ rowSecurity : table . rowSecurity ,
1792
+ permissions : table [ '$permissions' ]
1782
1793
} )
1783
1794
1784
- success ( `Updated ${ table . name } ( ${ table [ '$id' ] } ) name` ) ;
1795
+ success ( `Updated ${ table . name } ( ${ table [ '$id' ] } ) - ${ changes . join ( ', ' ) } ` ) ;
1796
+ tablesChanged . add ( table [ '$id' ] ) ;
1785
1797
}
1786
1798
table . remoteVersion = remoteTable ;
1787
1799
@@ -1794,16 +1806,19 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
1794
1806
databaseId : table [ 'databaseId' ] ,
1795
1807
tableId : table [ '$id' ] ,
1796
1808
name : table . name ,
1797
- documentSecurity : table . documentSecurity ,
1809
+ rowSecurity : table . rowSecurity ,
1798
1810
permissions : table [ '$permissions' ] ,
1799
1811
parseOutput : false
1800
1812
} )
1813
+
1814
+ success ( `Created ${ table . name } ( ${ table [ '$id' ] } )` ) ;
1815
+ tablesChanged . add ( table [ '$id' ] ) ;
1801
1816
} else {
1802
1817
throw e ;
1803
1818
}
1804
1819
}
1805
1820
} ) )
1806
- let numberOfTables = 0 ;
1821
+
1807
1822
// Serialize attribute actions
1808
1823
for ( let table of tables ) {
1809
1824
let columns = table . columns ;
@@ -1831,11 +1846,11 @@ const pushTable = async ({ returnOnZero, attempts } = { returnOnZero: false }) =
1831
1846
} catch ( e ) {
1832
1847
throw e ;
1833
1848
}
1834
- numberOfTables ++ ;
1849
+ tablesChanged . add ( table [ '$id' ] ) ;
1835
1850
success ( `Successfully pushed ${ table . name } ( ${ table [ '$id' ] } )` ) ;
1836
1851
}
1837
1852
1838
- success ( `Successfully pushed ${ numberOfTables } tables` ) ;
1853
+ success ( `Successfully pushed ${ tablesChanged . size } tables` ) ;
1839
1854
}
1840
1855
1841
1856
const pushCollection = async ( { returnOnZero, attempts } = { returnOnZero : false } ) => {
0 commit comments