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

Align schema commands with public schema endpoints #570

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ test-results.xml
/test/test-homedir

# default fauna config file names
fauna.config.yaml,
fauna.config.yml,
fauna.config.json,
.fauna.config.yaml,
.fauna.config.yml,
.fauna.config.json,
fauna.config.yaml
fauna.config.yml
fauna.config.json
.fauna.config.yaml
.fauna.config.yml
.fauna.config.json
7 changes: 1 addition & 6 deletions src/commands/schema/abandon.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,16 @@ async function doAbandon(argv) {
const secret = await getSecret(argv);

if (!argv.input) {
const params = new URLSearchParams({
force: "true", // Just abandon, don't pass a schema version through.
});

await makeFaunaRequest({
argv,
path: "/schema/1/staged/abandon",
params,
method: "POST",
secret,
});
logger.stdout("Schema has been abandoned.");
} else {
// Show status to confirm.
const params = new URLSearchParams({ diff: "true" });
const params = new URLSearchParams({ format: "semantic" });

const response = await makeFaunaRequest({
argv,
Expand Down
7 changes: 1 addition & 6 deletions src/commands/schema/commit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,17 @@ async function doCommit(argv) {
const secret = await getSecret(argv);

if (!argv.input) {
const params = new URLSearchParams({
force: "true", // Just commit, don't pass a schema version through.
});

await makeFaunaRequest({
argv,
path: "/schema/1/staged/commit",
params,
method: "POST",
secret,
});

logger.stdout("Schema has been committed");
} else {
// Show status to confirm.
const params = new URLSearchParams({ diff: "true" });
const params = new URLSearchParams({ format: "semantic" });

const response = await makeFaunaRequest({
argv,
Expand Down
10 changes: 4 additions & 6 deletions src/commands/schema/diff.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,22 @@ function parseTarget(argv) {
function buildStatusParams(argv) {
const params = new URLSearchParams({});
const [, target] = parseTarget(argv);
const diffKind = argv.text ? "textual" : "semantic";
const format = argv.text ? "textual" : "semantic";

if (target === "staged") params.set("diff", diffKind);
if (target === "staged") params.set("format", format);

return params;
}

function buildValidateParams(argv, version) {
const [source] = parseTarget(argv);
const diffKind = argv.text ? "textual" : "semantic";
const format = argv.text ? "textual" : "semantic";
const params = new URLSearchParams({
diff: diffKind,
format,
staged: String(source === "staged"),
});
if (version) {
params.set("version", version);
} else {
params.set("force", "true");
}

return params;
Expand Down
1 change: 0 additions & 1 deletion src/commands/schema/push.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export async function pushSchema(argv) {
);
} else if (!argv.input) {
const params = new URLSearchParams({
force: "true",
staged: argv.active ? "false" : "true",
});

Expand Down
13 changes: 5 additions & 8 deletions test/commands/local.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,11 @@ Please pass a --host-port other than '8443'.",
await run(`local --no-color ${args}`, container);

expect(gatherFSL).to.have.been.calledWith("bar");
expect(fetch).to.have.been.calledWith(
`${baseUrl}/update?force=true&staged=false`,
{
method: "POST",
headers: { AUTHORIZATION: "Bearer secret:Foo:admin" },
body: reformatFSL(fsl),
},
);
expect(fetch).to.have.been.calledWith(`${baseUrl}/update?staged=false`, {
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'.",
Expand Down
17 changes: 13 additions & 4 deletions test/commands/schema/abandon.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("schema abandon", function () {

expect(fetch).to.have.been.calledOnce;
expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/staged/abandon", { force: "true" }),
buildUrl("/schema/1/staged/abandon"),
{ ...commonFetchParams, method: "POST" },
);
expect(logger.stdout).to.have.been.calledWith("Schema has been abandoned.");
Expand All @@ -65,7 +65,10 @@ describe("schema abandon", function () {
await run(`schema abandon --secret "secret"`, container);

expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/staged/status", { diff: "true", color: "ansi" }),
buildUrl("/schema/1/staged/status", {
format: "semantic",
color: "ansi",
}),
{ ...commonFetchParams, method: "GET" },
);
expect(fetch).to.have.been.calledWith(
Expand Down Expand Up @@ -93,7 +96,10 @@ describe("schema abandon", function () {
expect(logger.stderr).to.have.been.calledWith(message);

expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/staged/status", { diff: "true", color: "ansi" }),
buildUrl("/schema/1/staged/status", {
format: "semantic",
color: "ansi",
}),
{ ...commonFetchParams, method: "GET" },
);
});
Expand All @@ -117,7 +123,10 @@ describe("schema abandon", function () {

expect(fetch).to.have.been.calledOnce;
expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/staged/status", { diff: "true", color: "ansi" }),
buildUrl("/schema/1/staged/status", {
format: "semantic",
color: "ansi",
}),
{ ...commonFetchParams, method: "GET" },
);
expect(logger.stdout).to.have.been.calledWith("Abandon cancelled.");
Expand Down
28 changes: 20 additions & 8 deletions test/commands/schema/commit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ describe("schema commit", function () {
await run(`schema commit --secret "secret"`, container);

expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/staged/status", { diff: "true", color: "ansi" }),
buildUrl("/schema/1/staged/status", {
format: "semantic",
color: "ansi",
}),
{ ...commonFetchParams, method: "GET" },
);
expect(fetch).to.have.been.calledWith(
Expand All @@ -62,10 +65,10 @@ describe("schema commit", function () {
await run(`schema commit --secret "secret" --no-input`, container);

expect(fetch).to.have.been.calledOnce;
expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/staged/commit", { force: "true" }),
{ ...commonFetchParams, method: "POST" },
);
expect(fetch).to.have.been.calledWith(buildUrl("/schema/1/staged/commit"), {
...commonFetchParams,
method: "POST",
});
expect(logger.stdout).to.have.been.calledWith("Schema has been committed");
expect(logger.stderr).to.not.have.been.called;
expect(confirm).to.not.have.been.called;
Expand All @@ -81,7 +84,10 @@ describe("schema commit", function () {
expect(error).to.have.property("code", 1);
expect(fetch).to.have.been.calledOnce;
expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/staged/status", { diff: "true", color: "ansi" }),
buildUrl("/schema/1/staged/status", {
format: "semantic",
color: "ansi",
}),
{ ...commonFetchParams, method: "GET" },
);
expect(logger.stdout).to.not.have.been.called;
Expand All @@ -100,7 +106,10 @@ describe("schema commit", function () {
expect(error).to.have.property("code", 1);
expect(fetch).to.have.been.calledOnce;
expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/staged/status", { diff: "true", color: "ansi" }),
buildUrl("/schema/1/staged/status", {
format: "semantic",
color: "ansi",
}),
{ ...commonFetchParams, method: "GET" },
);
expect(logger.stdout).to.have.been.calledWith(diff);
Expand All @@ -127,7 +136,10 @@ describe("schema commit", function () {

expect(fetch).to.have.been.calledOnce;
expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/staged/status", { diff: "true", color: "ansi" }),
buildUrl("/schema/1/staged/status", {
format: "semantic",
color: "ansi",
}),
{ ...commonFetchParams, method: "GET" },
);
expect(logger.stdout).to.have.been.calledWith("Commit cancelled");
Expand Down
12 changes: 4 additions & 8 deletions test/commands/schema/diff.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ describe("schema diff", function () {
expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/diff", {
color: "ansi",
diff: "semantic",
force: "true",
format: "semantic",
staged: "true",
}),
{ ...commonFetchParams, method: "POST", body: reformatFSL(fsl) },
Expand All @@ -74,8 +73,7 @@ describe("schema diff", function () {
expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/diff", {
color: "ansi",
diff: "semantic",
force: "true",
format: "semantic",
staged: "false",
}),
{ ...commonFetchParams, method: "POST", body: reformatFSL(fsl) },
Expand All @@ -100,9 +98,8 @@ describe("schema diff", function () {
});
expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/diff", {
force: "true",
staged: "true",
diff: "semantic",
format: "semantic",
}),
{ ...commonFetchParams, method: "POST", body: reformatFSL(fsl) },
);
Expand All @@ -126,10 +123,9 @@ describe("schema diff", function () {
);
expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/diff", {
force: "true",
color: "ansi",
staged: "true",
diff: "semantic",
format: "semantic",
}),
{ ...commonFetchParams, method: "POST", body: reformatFSL(fsl) },
);
Expand Down
2 changes: 1 addition & 1 deletion test/commands/schema/push.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe("schema push", function () {
expect(gatherFSL).to.have.been.calledWith(".");

expect(fetch).to.have.been.calledWith(
buildUrl("/schema/1/update", { force: "true", staged: "true" }),
buildUrl("/schema/1/update", { staged: "true" }),
{
method: "POST",
headers: { AUTHORIZATION: "Bearer secret" },
Expand Down