Skip to content

Commit 094e8dd

Browse files
committed
feat(cli): Non destructive db, starting
1 parent c91aa21 commit 094e8dd

File tree

1 file changed

+31
-41
lines changed

1 file changed

+31
-41
lines changed

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

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -787,29 +787,18 @@ const pushCollection = async ({ all, yes } = {}) => {
787787
throw e;
788788
}
789789
}
790-
791-
// Create all non-relationship attributes first
792790
const attributes = collection.attributes.filter(attribute => attribute.type !== 'relationship');
791+
const relationshipAttributes = collection.attributes.filter(attribute => attribute.type === 'relationship' && attribute.side === 'parent');
793792

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;
806797
}
807798

808-
success(`Created ${attributes.length} non-relationship attributes`);
809-
810799
log(`Creating indexes ...`)
811800

812-
await Promise.all(collection.indexes.map(async index => {
801+
for (let index of collections.indexes) {
813802
await databasesCreateIndex({
814803
databaseId,
815804
collectionId: collection['$id'],
@@ -819,7 +808,7 @@ const pushCollection = async ({ all, yes } = {}) => {
819808
orders: index.orders,
820809
parseOutput: false
821810
});
822-
}));
811+
}
823812

824813
result = await awaitPools.expectIndexes(
825814
databaseId,
@@ -831,39 +820,40 @@ const pushCollection = async ({ all, yes } = {}) => {
831820
throw new Error("Index creation timed out.");
832821
}
833822

834-
success(`Created ${collection.indexes.length} indexes`);
823+
for (let attribute of collection.attributes) {
824+
await createAttribute(databaseId, collection['$id'], attribute);
825+
}
835826

836-
success(`Pushed ${collection.name} ( ${collection['$id']} )`);
837-
}
827+
success(`Created ${collection.indexes.length} indexes`);
838828

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-
);
844829

845-
if (relationships.length === 0) {
846-
continue;
830+
try {
831+
await createAttributes(relationshipAttributes, 'relationship attributes')
832+
} catch (e) {
833+
throw e;
847834
}
848835

849-
log(`Pushing relationships for collection ${collection.name} ( ${collection['$id']} )`);
850836

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+
}
854840

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+
}
860845

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+
);
864851

865-
success(`Created ${relationships.length} relationship attributes`);
852+
if (!result) {
853+
throw new Error(`Attribute creation timed out.`);
866854
}
855+
856+
success(`Created ${attributes.length} ${title}`);
867857
}
868858

869859
const pushBucket = async ({ all, yes } = {}) => {

0 commit comments

Comments
 (0)