refactor: ColumnSpec / AddColumn carry constraint fields (ADR-0029 scaffolding)
Expand ColumnSpec and Command::AddColumn with the four ADR-0029 constraint slots (not_null, unique, default, check), all defaulting off; `Database::add_column` now takes a ColumnSpec. No behaviour change — the grammar to set the fields and the DDL to enforce them land in the following commits. Isolated here so those commits stay readable. Adds ColumnSpec::new for the unconstrained case; 110 call sites updated. 1172 tests pass; clippy clean.
This commit is contained in:
@@ -45,8 +45,8 @@ fn enrich_unique_insert_resolves_table_column_value_and_pinpoint() {
|
||||
db.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![
|
||||
ColumnSpec { name: "id".to_string(), ty: Type::Int },
|
||||
ColumnSpec { name: "name".to_string(), ty: Type::Text },
|
||||
ColumnSpec::new("id".to_string(), Type::Int),
|
||||
ColumnSpec::new("name".to_string(), Type::Text),
|
||||
],
|
||||
vec!["id".to_string()],
|
||||
None,
|
||||
@@ -109,7 +109,7 @@ fn enrich_unique_insert_natural_order_short_form_resolves_value_via_schema() {
|
||||
rt().block_on(async {
|
||||
db.create_table(
|
||||
"thing".to_string(),
|
||||
vec![ColumnSpec { name: "id".to_string(), ty: Type::Int }],
|
||||
vec![ColumnSpec::new("id".to_string(), Type::Int)],
|
||||
vec!["id".to_string()],
|
||||
None,
|
||||
)
|
||||
@@ -152,8 +152,8 @@ fn enrich_unique_update_resolves_value_from_assignments() {
|
||||
db.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![
|
||||
ColumnSpec { name: "id".to_string(), ty: Type::Int },
|
||||
ColumnSpec { name: "name".to_string(), ty: Type::Text },
|
||||
ColumnSpec::new("id".to_string(), Type::Int),
|
||||
ColumnSpec::new("name".to_string(), Type::Text),
|
||||
],
|
||||
vec!["id".to_string()],
|
||||
None,
|
||||
@@ -215,8 +215,8 @@ fn enrich_not_null_resolves_table_and_column() {
|
||||
db.create_table(
|
||||
"T".to_string(),
|
||||
vec![
|
||||
ColumnSpec { name: "a".to_string(), ty: Type::Int },
|
||||
ColumnSpec { name: "b".to_string(), ty: Type::Text },
|
||||
ColumnSpec::new("a".to_string(), Type::Int),
|
||||
ColumnSpec::new("b".to_string(), Type::Text),
|
||||
],
|
||||
vec!["a".to_string(), "b".to_string()],
|
||||
None,
|
||||
@@ -258,7 +258,7 @@ fn enrich_fk_insert_resolves_parent_table_column_and_value() {
|
||||
rt().block_on(async {
|
||||
db.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![ColumnSpec { name: "id".to_string(), ty: Type::Int }],
|
||||
vec![ColumnSpec::new("id".to_string(), Type::Int)],
|
||||
vec!["id".to_string()],
|
||||
None,
|
||||
)
|
||||
@@ -267,8 +267,8 @@ fn enrich_fk_insert_resolves_parent_table_column_and_value() {
|
||||
db.create_table(
|
||||
"Orders".to_string(),
|
||||
vec![
|
||||
ColumnSpec { name: "id".to_string(), ty: Type::Int },
|
||||
ColumnSpec { name: "CustId".to_string(), ty: Type::Int },
|
||||
ColumnSpec::new("id".to_string(), Type::Int),
|
||||
ColumnSpec::new("CustId".to_string(), Type::Int),
|
||||
],
|
||||
vec!["id".to_string()],
|
||||
None,
|
||||
@@ -333,7 +333,7 @@ fn enrich_fk_insert_natural_order_multi_value_resolves_via_schema() {
|
||||
rt().block_on(async {
|
||||
db.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![ColumnSpec { name: "id".to_string(), ty: Type::Int }],
|
||||
vec![ColumnSpec::new("id".to_string(), Type::Int)],
|
||||
vec!["id".to_string()],
|
||||
None,
|
||||
)
|
||||
@@ -342,9 +342,9 @@ fn enrich_fk_insert_natural_order_multi_value_resolves_via_schema() {
|
||||
db.create_table(
|
||||
"Orders".to_string(),
|
||||
vec![
|
||||
ColumnSpec { name: "id".to_string(), ty: Type::Serial },
|
||||
ColumnSpec { name: "CustId".to_string(), ty: Type::Int },
|
||||
ColumnSpec { name: "Total".to_string(), ty: Type::Real },
|
||||
ColumnSpec::new("id".to_string(), Type::Serial),
|
||||
ColumnSpec::new("CustId".to_string(), Type::Int),
|
||||
ColumnSpec::new("Total".to_string(), Type::Real),
|
||||
],
|
||||
vec!["id".to_string()],
|
||||
None,
|
||||
@@ -408,7 +408,7 @@ fn enrich_fk_delete_resolves_child_table() {
|
||||
rt().block_on(async {
|
||||
db.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![ColumnSpec { name: "id".to_string(), ty: Type::Int }],
|
||||
vec![ColumnSpec::new("id".to_string(), Type::Int)],
|
||||
vec!["id".to_string()],
|
||||
None,
|
||||
)
|
||||
@@ -417,8 +417,8 @@ fn enrich_fk_delete_resolves_child_table() {
|
||||
db.create_table(
|
||||
"Orders".to_string(),
|
||||
vec![
|
||||
ColumnSpec { name: "id".to_string(), ty: Type::Int },
|
||||
ColumnSpec { name: "CustId".to_string(), ty: Type::Int },
|
||||
ColumnSpec::new("id".to_string(), Type::Int),
|
||||
ColumnSpec::new("CustId".to_string(), Type::Int),
|
||||
],
|
||||
vec!["id".to_string()],
|
||||
None,
|
||||
|
||||
@@ -66,8 +66,8 @@ fn create_table_writes_yaml_and_history() {
|
||||
db.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![
|
||||
ColumnSpec { name: "id".to_string(), ty: Type::Serial },
|
||||
ColumnSpec { name: "Name".to_string(), ty: Type::Text },
|
||||
ColumnSpec::new("id".to_string(), Type::Serial),
|
||||
ColumnSpec::new("Name".to_string(), Type::Text),
|
||||
],
|
||||
vec!["id".to_string()],
|
||||
Some("create table Customers with pk id(serial)".to_string()),
|
||||
@@ -96,8 +96,8 @@ fn insert_writes_csv_and_history() {
|
||||
db.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![
|
||||
ColumnSpec { name: "id".to_string(), ty: Type::Serial },
|
||||
ColumnSpec { name: "Name".to_string(), ty: Type::Text },
|
||||
ColumnSpec::new("id".to_string(), Type::Serial),
|
||||
ColumnSpec::new("Name".to_string(), Type::Text),
|
||||
],
|
||||
vec!["id".to_string()],
|
||||
Some("create table Customers with pk id(serial)".to_string()),
|
||||
@@ -134,7 +134,7 @@ fn drop_table_removes_its_csv() {
|
||||
rt().block_on(async {
|
||||
db.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![ColumnSpec { name: "id".to_string(), ty: Type::Serial }],
|
||||
vec![ColumnSpec::new("id".to_string(), Type::Serial)],
|
||||
vec!["id".to_string()],
|
||||
Some("create table Customers with pk id(serial)".to_string()),
|
||||
)
|
||||
@@ -172,7 +172,7 @@ fn delete_with_cascade_rewrites_both_csvs() {
|
||||
rt().block_on(async {
|
||||
db.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![ColumnSpec { name: "id".to_string(), ty: Type::Serial }],
|
||||
vec![ColumnSpec::new("id".to_string(), Type::Serial)],
|
||||
vec!["id".to_string()],
|
||||
Some("create table Customers with pk id(serial)".to_string()),
|
||||
)
|
||||
@@ -181,8 +181,8 @@ fn delete_with_cascade_rewrites_both_csvs() {
|
||||
db.create_table(
|
||||
"Orders".to_string(),
|
||||
vec![
|
||||
ColumnSpec { name: "id".to_string(), ty: Type::Serial },
|
||||
ColumnSpec { name: "CustId".to_string(), ty: Type::Int },
|
||||
ColumnSpec::new("id".to_string(), Type::Serial),
|
||||
ColumnSpec::new("CustId".to_string(), Type::Int),
|
||||
],
|
||||
vec!["id".to_string()],
|
||||
Some("create table Orders with pk id(serial), CustId(int)".to_string()),
|
||||
@@ -259,8 +259,8 @@ fn create_table_does_not_write_csv_for_empty_table() {
|
||||
db.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![
|
||||
ColumnSpec { name: "id".to_string(), ty: Type::Serial },
|
||||
ColumnSpec { name: "Name".to_string(), ty: Type::Text },
|
||||
ColumnSpec::new("id".to_string(), Type::Serial),
|
||||
ColumnSpec::new("Name".to_string(), Type::Text),
|
||||
],
|
||||
vec!["id".to_string()],
|
||||
Some("create table Customers with pk id(serial)".to_string()),
|
||||
@@ -288,8 +288,8 @@ fn delete_all_rows_removes_csv() {
|
||||
db.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![
|
||||
ColumnSpec { name: "id".to_string(), ty: Type::Serial },
|
||||
ColumnSpec { name: "Name".to_string(), ty: Type::Text },
|
||||
ColumnSpec::new("id".to_string(), Type::Serial),
|
||||
ColumnSpec::new("Name".to_string(), Type::Text),
|
||||
],
|
||||
vec!["id".to_string()],
|
||||
Some("create table Customers with pk id(serial)".to_string()),
|
||||
@@ -330,7 +330,7 @@ fn show_table_appends_history_only() {
|
||||
rt().block_on(async {
|
||||
db.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![ColumnSpec { name: "id".to_string(), ty: Type::Serial }],
|
||||
vec![ColumnSpec::new("id".to_string(), Type::Serial)],
|
||||
vec!["id".to_string()],
|
||||
Some("create table Customers with pk id(serial)".to_string()),
|
||||
)
|
||||
@@ -363,7 +363,7 @@ fn failed_command_does_not_append_history_or_change_yaml() {
|
||||
rt().block_on(async {
|
||||
db.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![ColumnSpec { name: "id".to_string(), ty: Type::Serial }],
|
||||
vec![ColumnSpec::new("id".to_string(), Type::Serial)],
|
||||
vec!["id".to_string()],
|
||||
Some("create table Customers with pk id(serial)".to_string()),
|
||||
)
|
||||
@@ -375,7 +375,7 @@ fn failed_command_does_not_append_history_or_change_yaml() {
|
||||
let err = db
|
||||
.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![ColumnSpec { name: "id".to_string(), ty: Type::Serial }],
|
||||
vec![ColumnSpec::new("id".to_string(), Type::Serial)],
|
||||
vec!["id".to_string()],
|
||||
Some("create table Customers with pk id(serial)".to_string()),
|
||||
)
|
||||
@@ -404,7 +404,7 @@ fn project_yaml_carries_relationship_after_add() {
|
||||
rt().block_on(async {
|
||||
db.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![ColumnSpec { name: "id".to_string(), ty: Type::Serial }],
|
||||
vec![ColumnSpec::new("id".to_string(), Type::Serial)],
|
||||
vec!["id".to_string()],
|
||||
None,
|
||||
)
|
||||
@@ -413,8 +413,8 @@ fn project_yaml_carries_relationship_after_add() {
|
||||
db.create_table(
|
||||
"Orders".to_string(),
|
||||
vec![
|
||||
ColumnSpec { name: "id".to_string(), ty: Type::Serial },
|
||||
ColumnSpec { name: "CustId".to_string(), ty: Type::Int },
|
||||
ColumnSpec::new("id".to_string(), Type::Serial),
|
||||
ColumnSpec::new("CustId".to_string(), Type::Int),
|
||||
],
|
||||
vec!["id".to_string()],
|
||||
None,
|
||||
|
||||
+13
-14
@@ -44,8 +44,8 @@ fn rebuild_restores_schema_only_project() {
|
||||
db.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![
|
||||
ColumnSpec { name: "id".to_string(), ty: Type::Serial },
|
||||
ColumnSpec { name: "Name".to_string(), ty: Type::Text },
|
||||
ColumnSpec::new("id".to_string(), Type::Serial),
|
||||
ColumnSpec::new("Name".to_string(), Type::Text),
|
||||
],
|
||||
vec!["id".to_string()],
|
||||
Some("create table Customers with pk id(serial)".to_string()),
|
||||
@@ -98,8 +98,8 @@ fn rebuild_restores_rows_from_csv() {
|
||||
db.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![
|
||||
ColumnSpec { name: "id".to_string(), ty: Type::Serial },
|
||||
ColumnSpec { name: "Name".to_string(), ty: Type::Text },
|
||||
ColumnSpec::new("id".to_string(), Type::Serial),
|
||||
ColumnSpec::new("Name".to_string(), Type::Text),
|
||||
],
|
||||
vec!["id".to_string()],
|
||||
Some("create".to_string()),
|
||||
@@ -165,7 +165,7 @@ fn rebuild_restores_relationships_and_cascade_behaviour() {
|
||||
rt().block_on(async {
|
||||
db.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![ColumnSpec { name: "id".to_string(), ty: Type::Serial }],
|
||||
vec![ColumnSpec::new("id".to_string(), Type::Serial)],
|
||||
vec!["id".to_string()],
|
||||
Some("create".to_string()),
|
||||
)
|
||||
@@ -174,8 +174,8 @@ fn rebuild_restores_relationships_and_cascade_behaviour() {
|
||||
db.create_table(
|
||||
"Orders".to_string(),
|
||||
vec![
|
||||
ColumnSpec { name: "id".to_string(), ty: Type::Serial },
|
||||
ColumnSpec { name: "CustId".to_string(), ty: Type::Int },
|
||||
ColumnSpec::new("id".to_string(), Type::Serial),
|
||||
ColumnSpec::new("CustId".to_string(), Type::Int),
|
||||
],
|
||||
vec!["id".to_string()],
|
||||
Some("create".to_string()),
|
||||
@@ -265,8 +265,8 @@ fn rebuild_reports_fatal_error_on_bad_csv_row() {
|
||||
db.create_table(
|
||||
"Numbers".to_string(),
|
||||
vec![
|
||||
ColumnSpec { name: "id".to_string(), ty: Type::Serial },
|
||||
ColumnSpec { name: "n".to_string(), ty: Type::Int },
|
||||
ColumnSpec::new("id".to_string(), Type::Serial),
|
||||
ColumnSpec::new("n".to_string(), Type::Int),
|
||||
],
|
||||
vec!["id".to_string()],
|
||||
Some("create".to_string()),
|
||||
@@ -326,7 +326,7 @@ fn rebuild_preserves_created_at_from_yaml() {
|
||||
rt().block_on(async {
|
||||
db.create_table(
|
||||
"T".to_string(),
|
||||
vec![ColumnSpec { name: "id".to_string(), ty: Type::Serial }],
|
||||
vec![ColumnSpec::new("id".to_string(), Type::Serial)],
|
||||
vec!["id".to_string()],
|
||||
Some("create".to_string()),
|
||||
)
|
||||
@@ -377,8 +377,7 @@ fn rebuild_preserves_created_at_from_yaml() {
|
||||
// describe is read-only; force a rewrite by adding a column.
|
||||
db.add_column(
|
||||
"T".to_string(),
|
||||
"Note".to_string(),
|
||||
Type::Text,
|
||||
ColumnSpec::new("Note", Type::Text),
|
||||
Some("add column".to_string()),
|
||||
)
|
||||
.await
|
||||
@@ -410,8 +409,8 @@ fn rebuild_restores_indexes() {
|
||||
db.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![
|
||||
ColumnSpec { name: "id".to_string(), ty: Type::Serial },
|
||||
ColumnSpec { name: "Email".to_string(), ty: Type::Text },
|
||||
ColumnSpec::new("id".to_string(), Type::Serial),
|
||||
ColumnSpec::new("Email".to_string(), Type::Text),
|
||||
],
|
||||
vec!["id".to_string()],
|
||||
Some("create table Customers with pk id(serial)".to_string()),
|
||||
|
||||
@@ -131,8 +131,8 @@ fn rebuild_against_populated_db_wipes_and_reloads() {
|
||||
db.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![
|
||||
ColumnSpec { name: "id".to_string(), ty: Type::Serial },
|
||||
ColumnSpec { name: "Name".to_string(), ty: Type::Text },
|
||||
ColumnSpec::new("id".to_string(), Type::Serial),
|
||||
ColumnSpec::new("Name".to_string(), Type::Text),
|
||||
],
|
||||
vec!["id".to_string()],
|
||||
Some("create".to_string()),
|
||||
|
||||
@@ -388,7 +388,7 @@ fn temp_with_a_table_is_no_longer_unmodified() {
|
||||
rt.block_on(async {
|
||||
db.create_table(
|
||||
"T".to_string(),
|
||||
vec![ColumnSpec { name: "id".to_string(), ty: Type::Serial }],
|
||||
vec![ColumnSpec::new("id".to_string(), Type::Serial)],
|
||||
vec!["id".to_string()],
|
||||
Some("create".to_string()),
|
||||
)
|
||||
|
||||
@@ -299,8 +299,8 @@ fn end_to_end_export_then_import_real_project() {
|
||||
db.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![
|
||||
ColumnSpec { name: "id".to_string(), ty: Type::Serial },
|
||||
ColumnSpec { name: "Name".to_string(), ty: Type::Text },
|
||||
ColumnSpec::new("id".to_string(), Type::Serial),
|
||||
ColumnSpec::new("Name".to_string(), Type::Text),
|
||||
],
|
||||
vec!["id".to_string()],
|
||||
Some("create table Customers with pk id(serial)".to_string()),
|
||||
|
||||
@@ -165,14 +165,8 @@ fn db_persists_across_open_close_cycles() {
|
||||
db.create_table(
|
||||
"Customers".to_string(),
|
||||
vec![
|
||||
rdbms_playground::dsl::ColumnSpec {
|
||||
name: "id".to_string(),
|
||||
ty: rdbms_playground::dsl::Type::Serial,
|
||||
},
|
||||
rdbms_playground::dsl::ColumnSpec {
|
||||
name: "Name".to_string(),
|
||||
ty: rdbms_playground::dsl::Type::Text,
|
||||
},
|
||||
rdbms_playground::dsl::ColumnSpec::new("id".to_string(), rdbms_playground::dsl::Type::Serial),
|
||||
rdbms_playground::dsl::ColumnSpec::new("Name".to_string(), rdbms_playground::dsl::Type::Text),
|
||||
],
|
||||
vec!["id".to_string()],
|
||||
None)
|
||||
|
||||
@@ -90,10 +90,7 @@ fn typing_then_submitting_a_dsl_command_emits_execute_action() {
|
||||
&actions,
|
||||
&Command::CreateTable {
|
||||
name: "Customers".to_string(),
|
||||
columns: vec![ColumnSpec {
|
||||
name: "id".to_string(),
|
||||
ty: Type::Serial,
|
||||
}],
|
||||
columns: vec![ColumnSpec::new("id".to_string(), Type::Serial)],
|
||||
primary_key: vec!["id".to_string()],
|
||||
},
|
||||
);
|
||||
@@ -271,10 +268,7 @@ fn create_table_flow_updates_tables_list_and_structure_view() {
|
||||
let actions = submit(&mut app);
|
||||
let expected_cmd = Command::CreateTable {
|
||||
name: "Customers".to_string(),
|
||||
columns: vec![ColumnSpec {
|
||||
name: "id".to_string(),
|
||||
ty: Type::Serial,
|
||||
}],
|
||||
columns: vec![ColumnSpec::new("id".to_string(), Type::Serial)],
|
||||
primary_key: vec!["id".to_string()],
|
||||
};
|
||||
assert_one_execute_dsl(&actions, &expected_cmd);
|
||||
@@ -326,6 +320,10 @@ fn add_column_flow_updates_structure_view() {
|
||||
table: "Customers".to_string(),
|
||||
column: "Name".to_string(),
|
||||
ty: Type::Text,
|
||||
not_null: false,
|
||||
unique: false,
|
||||
default: None,
|
||||
check: None,
|
||||
},
|
||||
);
|
||||
|
||||
@@ -338,6 +336,10 @@ fn add_column_flow_updates_structure_view() {
|
||||
table: "Customers".to_string(),
|
||||
column: "Name".to_string(),
|
||||
ty: Type::Text,
|
||||
not_null: false,
|
||||
unique: false,
|
||||
default: None,
|
||||
check: None,
|
||||
},
|
||||
description: Some(updated.clone()),
|
||||
});
|
||||
@@ -479,6 +481,10 @@ fn add_relationship_flow_shows_inbound_section_on_parent() {
|
||||
table: "Customers".to_string(),
|
||||
column: "extra".to_string(),
|
||||
ty: Type::Text,
|
||||
not_null: false,
|
||||
unique: false,
|
||||
default: None,
|
||||
check: None,
|
||||
},
|
||||
description: Some(customers),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user