Skip to content

Commit

Permalink
✨ set OVERWRITE on schema/event creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Odonno committed Aug 12, 2024
1 parent 2d2389f commit 6e09c05
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 45 deletions.
10 changes: 5 additions & 5 deletions src/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn generate_file_content(
let field_definitions = generate_field_definitions(&args.fields, name.to_string());

format!(
"DEFINE TABLE {0} {1};
"DEFINE TABLE OVERWRITE {0} {1};
{2}",
name, table_schema_design_str, field_definitions
Expand All @@ -142,11 +142,11 @@ fn generate_file_content(
let field_definitions = generate_field_definitions(&args.fields, name.to_string());

format!(
"DEFINE TABLE {0} {1};
"DEFINE TABLE OVERWRITE {0} {1};
{2}
DEFINE EVENT {0} ON TABLE {0} WHEN $event == \"CREATE\" THEN (
DEFINE EVENT OVERWRITE {0} ON TABLE {0} WHEN $event == \"CREATE\" THEN (
# TODO
);",
name, table_schema_design_str, field_definitions
Expand Down Expand Up @@ -185,10 +185,10 @@ fn generate_field_definitions(fields: &Option<Vec<String>>, name: String) -> Str
match fields {
Some(fields) => fields
.iter()
.map(|field| format!("DEFINE FIELD {} ON {};", field, name))
.map(|field| format!("DEFINE FIELD OVERWRITE {} ON {};", field, name))
.collect::<Vec<String>>()
.join("\n"),
None => format!("# DEFINE FIELD field ON {};", name),
None => format!("# DEFINE FIELD OVERWRITE field ON {};", name),
}
}

Expand Down
40 changes: 20 additions & 20 deletions tests/cli/create/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ fn create_event_file() -> Result<()> {

assert_eq!(
publish_post_file,
"DEFINE TABLE publish_post SCHEMALESS;
"DEFINE TABLE OVERWRITE publish_post SCHEMALESS;
DEFINE FIELD post_id ON publish_post;
DEFINE FIELD created_at ON publish_post;
DEFINE FIELD OVERWRITE post_id ON publish_post;
DEFINE FIELD OVERWRITE created_at ON publish_post;
DEFINE EVENT publish_post ON TABLE publish_post WHEN $event == \"CREATE\" THEN (
DEFINE EVENT OVERWRITE publish_post ON TABLE publish_post WHEN $event == \"CREATE\" THEN (
# TODO
);",
);
Expand All @@ -51,12 +51,12 @@ fn create_event_file_dry_run() -> Result<()> {
.arg("--dry-run");

cmd.assert().success().stdout(
"DEFINE TABLE publish_post SCHEMALESS;
"DEFINE TABLE OVERWRITE publish_post SCHEMALESS;
DEFINE FIELD post_id ON publish_post;
DEFINE FIELD created_at ON publish_post;
DEFINE FIELD OVERWRITE post_id ON publish_post;
DEFINE FIELD OVERWRITE created_at ON publish_post;
DEFINE EVENT publish_post ON TABLE publish_post WHEN $event == \"CREATE\" THEN (
DEFINE EVENT OVERWRITE publish_post ON TABLE publish_post WHEN $event == \"CREATE\" THEN (
# TODO
);\n",
);
Expand Down Expand Up @@ -88,12 +88,12 @@ fn create_event_file_with_schemafull_table_from_config() -> Result<()> {

ensure!(
publish_post_file
== "DEFINE TABLE publish_post SCHEMAFULL;
== "DEFINE TABLE OVERWRITE publish_post SCHEMAFULL;
DEFINE FIELD post_id ON publish_post;
DEFINE FIELD created_at ON publish_post;
DEFINE FIELD OVERWRITE post_id ON publish_post;
DEFINE FIELD OVERWRITE created_at ON publish_post;
DEFINE EVENT publish_post ON TABLE publish_post WHEN $event == \"CREATE\" THEN (
DEFINE EVENT OVERWRITE publish_post ON TABLE publish_post WHEN $event == \"CREATE\" THEN (
# TODO
);",
"invalid publish post file string"
Expand Down Expand Up @@ -123,12 +123,12 @@ fn create_event_file_with_schemaless_table_from_invalid_config() -> Result<()> {

ensure!(
publish_post_file
== "DEFINE TABLE publish_post SCHEMALESS;
== "DEFINE TABLE OVERWRITE publish_post SCHEMALESS;
DEFINE FIELD post_id ON publish_post;
DEFINE FIELD created_at ON publish_post;
DEFINE FIELD OVERWRITE post_id ON publish_post;
DEFINE FIELD OVERWRITE created_at ON publish_post;
DEFINE EVENT publish_post ON TABLE publish_post WHEN $event == \"CREATE\" THEN (
DEFINE EVENT OVERWRITE publish_post ON TABLE publish_post WHEN $event == \"CREATE\" THEN (
# TODO
);",
"invalid publish post file string"
Expand Down Expand Up @@ -158,12 +158,12 @@ fn create_event_file_with_schemafull_table_from_cli_arg() -> Result<()> {

assert_eq!(
publish_post_file,
"DEFINE TABLE publish_post SCHEMAFULL;
"DEFINE TABLE OVERWRITE publish_post SCHEMAFULL;
DEFINE FIELD post_id ON publish_post;
DEFINE FIELD created_at ON publish_post;
DEFINE FIELD OVERWRITE post_id ON publish_post;
DEFINE FIELD OVERWRITE created_at ON publish_post;
DEFINE EVENT publish_post ON TABLE publish_post WHEN $event == \"CREATE\" THEN (
DEFINE EVENT OVERWRITE publish_post ON TABLE publish_post WHEN $event == \"CREATE\" THEN (
# TODO
);",
);
Expand Down
40 changes: 20 additions & 20 deletions tests/cli/create/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ fn create_schema_file() -> Result<()> {

assert_eq!(
post_file,
"DEFINE TABLE post SCHEMALESS;
"DEFINE TABLE OVERWRITE post SCHEMALESS;
DEFINE FIELD name ON post;
DEFINE FIELD title ON post;
DEFINE FIELD published_at ON post;"
DEFINE FIELD OVERWRITE name ON post;
DEFINE FIELD OVERWRITE title ON post;
DEFINE FIELD OVERWRITE published_at ON post;"
);

Ok(())
Expand All @@ -48,11 +48,11 @@ fn create_schema_file_dry_run() -> Result<()> {
.arg("--dry-run");

cmd.assert().success().stdout(
"DEFINE TABLE post SCHEMALESS;
"DEFINE TABLE OVERWRITE post SCHEMALESS;
DEFINE FIELD name ON post;
DEFINE FIELD title ON post;
DEFINE FIELD published_at ON post;\n",
DEFINE FIELD OVERWRITE name ON post;
DEFINE FIELD OVERWRITE title ON post;
DEFINE FIELD OVERWRITE published_at ON post;\n",
);

let schemas_folder = temp_dir.join("schemas");
Expand Down Expand Up @@ -82,11 +82,11 @@ fn create_schemafull_table_file_from_config() -> Result<()> {

ensure!(
post_file
== "DEFINE TABLE post SCHEMAFULL;
== "DEFINE TABLE OVERWRITE post SCHEMAFULL;
DEFINE FIELD name ON post;
DEFINE FIELD title ON post;
DEFINE FIELD published_at ON post;",
DEFINE FIELD OVERWRITE name ON post;
DEFINE FIELD OVERWRITE title ON post;
DEFINE FIELD OVERWRITE published_at ON post;",
"Expected file contents to match"
);

Expand Down Expand Up @@ -114,11 +114,11 @@ fn create_schemaless_table_file_from_invalid_config() -> Result<()> {

ensure!(
post_file
== "DEFINE TABLE post SCHEMALESS;
== "DEFINE TABLE OVERWRITE post SCHEMALESS;
DEFINE FIELD name ON post;
DEFINE FIELD title ON post;
DEFINE FIELD published_at ON post;",
DEFINE FIELD OVERWRITE name ON post;
DEFINE FIELD OVERWRITE title ON post;
DEFINE FIELD OVERWRITE published_at ON post;",
"Expected file contents to match"
);

Expand Down Expand Up @@ -146,11 +146,11 @@ fn create_schemafull_table_file_from_cli_arg() -> Result<()> {

assert_eq!(
post_file,
"DEFINE TABLE post SCHEMAFULL;
"DEFINE TABLE OVERWRITE post SCHEMAFULL;
DEFINE FIELD name ON post;
DEFINE FIELD title ON post;
DEFINE FIELD published_at ON post;"
DEFINE FIELD OVERWRITE name ON post;
DEFINE FIELD OVERWRITE title ON post;
DEFINE FIELD OVERWRITE published_at ON post;"
);

Ok(())
Expand Down

0 comments on commit 6e09c05

Please sign in to comment.