@@ -787,29 +787,18 @@ const pushCollection = async ({ all, yes } = {}) => {
787
787
throw e;
788
788
}
789
789
}
790
-
791
- // Create all non-relationship attributes first
792
790
const attributes = collection.attributes.filter(attribute => attribute.type !== 'relationship');
791
+ const relationshipAttributes = collection.attributes.filter(attribute => attribute.type === 'relationship' && attribute.side === 'parent');
793
792
794
- await Promise.all(attributes.map(attribute => {
795
- return createAttribute(databaseId, collection['$id'], attribute);
796
- }));
797
-
798
- let result = await awaitPools.expectAttributes(
799
- databaseId,
800
- collection['$id'],
801
- attributes.map(attribute => attribute.key)
802
- );
803
-
804
- if (!result) {
805
- throw new Error("Attribute creation timed out.");
793
+ try {
794
+ await createAttributes(attributes, 'attributes')
795
+ } catch (e) {
796
+ throw e;
806
797
}
807
798
808
- success(`Created ${attributes.length} non-relationship attributes`);
809
-
810
799
log(`Creating indexes ...`)
811
800
812
- await Promise.all(collection.indexes.map(async index => {
801
+ for (let index of collections.indexes) {
813
802
await databasesCreateIndex({
814
803
databaseId,
815
804
collectionId: collection['$id'],
@@ -819,7 +808,7 @@ const pushCollection = async ({ all, yes } = {}) => {
819
808
orders: index.orders,
820
809
parseOutput: false
821
810
});
822
- }));
811
+ }
823
812
824
813
result = await awaitPools.expectIndexes(
825
814
databaseId,
@@ -831,39 +820,40 @@ const pushCollection = async ({ all, yes } = {}) => {
831
820
throw new Error("Index creation timed out.");
832
821
}
833
822
834
- success(`Created ${collection.indexes.length} indexes`);
823
+ for (let attribute of collection.attributes) {
824
+ await createAttribute(databaseId, collection['$id'], attribute);
825
+ }
835
826
836
- success(`Pushed ${collection.name} ( ${collection['$id']} )`);
837
- }
827
+ success(`Created ${collection.indexes.length} indexes`);
838
828
839
- // Create the relationship attributes
840
- for (let collection of collections) {
841
- const relationships = collection.attributes.filter(attribute =>
842
- attribute.type === 'relationship' && attribute.side === 'parent'
843
- );
844
829
845
- if (relationships.length === 0) {
846
- continue;
830
+ try {
831
+ await createAttributes(relationshipAttributes, 'relationship attributes')
832
+ } catch (e) {
833
+ throw e;
847
834
}
848
835
849
- log(`Pushing relationships for collection ${collection.name} ( ${collection['$id']} )`);
850
836
851
- await Promise.all(relationships.map(attribute => {
852
- return createAttribute(collection['databaseId'], collection['$id'], attribute);
853
- }));
837
+ success(`Pushed ${collection.name} ( ${collection['$id']} )`);
838
+ }
839
+ }
854
840
855
- let result = await awaitPools.expectAttributes(
856
- collection['databaseId'],
857
- collection['$id'],
858
- relationships.map(attribute => attribute.key)
859
- );
841
+ const createAttributes = async (attributes, title) => {
842
+ for (let attribute of attributes) {
843
+ await createAttribute(databaseId, collection['$id'], attribute);
844
+ }
860
845
861
- if (!result) {
862
- throw new Error("Attribute creation timed out.");
863
- }
846
+ let result = await awaitPools.expectAttributes(
847
+ databaseId,
848
+ collection['$id'],
849
+ collection.attributes.map(attribute => attribute.key)
850
+ );
864
851
865
- success(`Created ${relationships.length} relationship attributes`);
852
+ if (!result) {
853
+ throw new Error(`Attribute creation timed out.`);
866
854
}
855
+
856
+ success(`Created ${attributes.length} ${title}`);
867
857
}
868
858
869
859
const pushBucket = async ({ all, yes } = {}) => {
0 commit comments