diff --git a/src/commands/local.mjs b/src/commands/local.mjs index ec87683f..3b5b52f9 100644 --- a/src/commands/local.mjs +++ b/src/commands/local.mjs @@ -47,7 +47,7 @@ async function createDatabaseSchema(argv) { ); // hack to let us push schema to the local database argv.secret = `secret:${argv.database}:admin`; - await pushSchema(argv); + await pushSchema({ ...argv, active: true, input: false }); logger.stderr( colorize( `[CreateDatabaseSchema] Schema for database '${argv.database}' created from directory '${argv.directory}'.`, @@ -186,17 +186,6 @@ function buildLocalCommand(yargs) { description: "Path to a local directory containing .fsl files for the database. Valid only if --database is set.", }, - active: { - description: - "Apply the local schema to the database's active schema. Skips staging the schema. Use --no-active to disable.", - type: "boolean", - default: true, - }, - input: { - description: "Prompt for input. Use --no-input to disable.", - default: true, - type: "boolean", - }, }) .check((argv) => { if (argv.maxAttempts < 1) { diff --git a/test/local.mjs b/test/local.mjs index e70e8145..32d7f562 100644 --- a/test/local.mjs +++ b/test/local.mjs @@ -21,11 +21,7 @@ describe("local command", () => { simulateError, startStub, unpauseStub, - gatherFSL, - confirm; - - const diffString = - "\u001b[1;34m* Modifying collection `Customer`\u001b[0m at collections.fsl:2:1:\n * Defined fields:\n\u001b[31m - drop field `.age`\u001b[0m\n\n"; + gatherFSL; const fsl = [ { @@ -45,7 +41,6 @@ describe("local command", () => { logsStub = stub(); startStub = stub(); unpauseStub = stub(); - confirm = container.resolve("confirm"); gatherFSL = container.resolve("gatherFSL"); gatherFSL.resolves(fsl); @@ -174,107 +169,33 @@ Please pass a --host-port other than '8443'.", const baseUrl = "http://0.0.0.0:8443/schema/1"; const { runQuery } = container.resolve("faunaClientV10"); - confirm.resolves(true); setupCreateContainerMocks(); runQuery.resolves({ data: JSON.stringify({ name: "Foo" }, null, 2), }); // The first call pings the container, then the second creates the diff... - fetch - .onCall(1) - .resolves( - f({ - version: 1728675598430000, - diff: diffString, - }), - ) - .onCall(2) - .resolves( - f({ - version: 1728675598430000, - }), - ); - - await run(`local --no-color ${args}`, container); - - expect(gatherFSL).to.have.been.calledWith("bar"); - expect(fetch).to.have.been.calledWith(`${baseUrl}/diff?staged=false`, { - method: "POST", - headers: { AUTHORIZATION: "Bearer secret:Foo:admin" }, - body: reformatFSL(fsl), - }); - expect(fetch).to.have.been.calledWith( - `${baseUrl}/update?staged=false&version=1728675598430000`, - { - method: "POST", - headers: { AUTHORIZATION: "Bearer secret:Foo:admin" }, - body: reformatFSL(fsl), - }, - ); - const written = stderrStream.getWritten(); - expect(written).to.contain( - "[CreateDatabaseSchema] Schema for database 'Foo' created from directory './bar'.", + fetch.onCall(1).resolves( + f({ + version: 1728675598430000, + }), ); - }); - }); - - [ - "--database Foo --dir ./bar --no-active", - "--database Foo --directory ./bar --no-active", - "--database Foo --project-directory ./bar --no-active", - ].forEach((args) => { - it(`Creates a staged schema without forcing if requested using ${args}`, async () => { - const baseUrl = "http://0.0.0.0:8443/schema/1"; - const { runQuery } = container.resolve("faunaClientV10"); - - confirm.resolves(true); - setupCreateContainerMocks(); - runQuery.resolves({ - data: JSON.stringify({ name: "Foo" }, null, 2), - }); - - // The first call pings the container, then the second creates the diff... - fetch - .onCall(1) - .resolves( - f({ - version: 1728675598430000, - diff: diffString, - }), - ) - .onCall(2) - .resolves( - f({ - version: 1728675598430000, - }), - ); await run(`local --no-color ${args}`, container); expect(gatherFSL).to.have.been.calledWith("bar"); - expect(fetch).to.have.been.calledWith(`${baseUrl}/diff?staged=true`, { - method: "POST", - headers: { AUTHORIZATION: "Bearer secret:Foo:admin" }, - body: reformatFSL(fsl), - }); expect(fetch).to.have.been.calledWith( - `${baseUrl}/update?staged=true&version=1728675598430000`, + `${baseUrl}/update?force=true&staged=false`, { method: "POST", headers: { AUTHORIZATION: "Bearer secret:Foo:admin" }, body: reformatFSL(fsl), }, ); - expect(logger.stdout).to.have.been.calledWith("Proposed diff:\n"); const written = stderrStream.getWritten(); expect(written).to.contain( "[CreateDatabaseSchema] Schema for database 'Foo' created from directory './bar'.", ); - expect(confirm).to.have.been.calledWith( - sinon.match.has("message", "Stage the above changes?"), - ); - expect(logger.stdout).to.have.been.calledWith(diffString); }); });