wip(freight): migration 0017 + model/column-list groundwork for add-freight-templates

This commit is contained in:
Chengdong Zhang
2026-09-23 17:39:45 +08:00
parent a83e857bdf
commit 5b426486ac
105 changed files with 6193 additions and 1566 deletions
+1
View File
@@ -68,4 +68,5 @@ pub struct SkuBody {
pub currency: String,
pub stock: i32,
pub active: Option<bool>,
pub weight_grams: Option<i32>,
}
+2 -2
View File
@@ -26,7 +26,7 @@ pub async fn attach_skus(
Vec::new()
} else if public_only {
sqlx::query_as::<_, Sku>(
"SELECT id, product_id, sku_code, attributes, price_minor, currency, stock, active
"SELECT id, product_id, sku_code, attributes, price_minor, currency, stock, weight_grams, active
FROM skus WHERE product_id = ANY($1) AND active = TRUE ORDER BY sku_code",
)
.bind(&ids)
@@ -34,7 +34,7 @@ pub async fn attach_skus(
.await?
} else {
sqlx::query_as::<_, Sku>(
"SELECT id, product_id, sku_code, attributes, price_minor, currency, stock, active
"SELECT id, product_id, sku_code, attributes, price_minor, currency, stock, weight_grams, active
FROM skus WHERE product_id = ANY($1) ORDER BY sku_code",
)
.bind(&ids)
+5 -4
View File
@@ -297,11 +297,11 @@ pub async fn upsert_sku(
)));
}
Ok(sqlx::query_as::<_, Sku>(
"INSERT INTO skus (product_id, sku_code, attributes, price_minor, currency, stock, active)
VALUES ($1, $2, $3, $4, $5, $6, $7)
"INSERT INTO skus (product_id, sku_code, attributes, price_minor, currency, stock, active, weight_grams)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
ON CONFLICT (product_id, sku_code)
DO UPDATE SET attributes = $3, price_minor = $4, currency = $5, stock = $6, active = $7
RETURNING id, product_id, sku_code, attributes, price_minor, currency, stock, active",
DO UPDATE SET attributes = $3, price_minor = $4, currency = $5, stock = $6, active = $7, weight_grams = $8
RETURNING id, product_id, sku_code, attributes, price_minor, currency, stock, weight_grams, active",
)
.bind(product_id)
.bind(body.sku_code.trim())
@@ -310,6 +310,7 @@ pub async fn upsert_sku(
.bind(&currency)
.bind(body.stock)
.bind(body.active.unwrap_or(true))
.bind(body.weight_grams)
.fetch_one(&state.db)
.await?)
}