Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove --active --no-input flags from fauna local #539

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions src/commands/local.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
);
// 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}'.`,
Expand Down Expand Up @@ -186,19 +186,8 @@
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) => {

Check warning on line 190 in src/commands/local.mjs

View workflow job for this annotation

GitHub Actions / lint

Arrow function has a complexity of 11. Maximum allowed is 10
if (argv.maxAttempts < 1) {
throw new ValidationError("--max-attempts must be greater than 0.");
}
Expand Down
91 changes: 6 additions & 85 deletions test/local.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand All @@ -45,7 +41,6 @@ describe("local command", () => {
logsStub = stub();
startStub = stub();
unpauseStub = stub();
confirm = container.resolve("confirm");

gatherFSL = container.resolve("gatherFSL");
gatherFSL.resolves(fsl);
Expand Down Expand Up @@ -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);
});
});

Expand Down
Loading