@@ -2,9 +2,9 @@ use crate::postgres_dao::ddl::ADMIN_DB_NAME;
22use async_trait:: async_trait;
33use chrono:: { DateTime , Utc } ;
44use concepts:: {
5- ComponentId , ComponentRetryConfig , ComponentType , ExecutionId , FunctionFqn , JoinSetId ,
6- StrVariant , SupportedFunctionReturnValue ,
7- component_id:: { ComponentDigest , Digest } ,
5+ ComponentId , ComponentRetryConfig , ComponentType , ContentDigest , ExecutionId , FunctionFqn ,
6+ JoinSetId , StrVariant , SupportedFunctionReturnValue ,
7+ component_id:: ComponentDigest ,
88 prefixed_ulid:: { DelayId , DeploymentId , ExecutionIdDerived , ExecutorId , RunId } ,
99 storage:: {
1010 AppendBatchResponse , AppendDelayResponseOutcome , AppendEventsToExecution , AppendRequest ,
@@ -297,6 +297,10 @@ impl PostgresPool {
297297 }
298298}
299299
300+ fn deployment_digest_from_pg_row ( row : & Row ) -> Result < ContentDigest , DbErrorRead > {
301+ Ok ( get ( row, "digest" ) ?)
302+ }
303+
300304fn deployment_record_from_pg_row ( row : & Row ) -> Result < DeploymentRecord , DbErrorRead > {
301305 let deployment_id_str: String = get ( row, "deployment_id" ) ?;
302306 let deployment_id = deployment_id_str. parse :: < DeploymentId > ( ) . map_err ( |e| {
@@ -309,6 +313,7 @@ fn deployment_record_from_pg_row(row: &Row) -> Result<DeploymentRecord, DbErrorR
309313 Ok ( DeploymentRecord {
310314 deployment_id,
311315 description : get ( row, "description" ) ?,
316+ digest : get ( row, "digest" ) ?,
312317 created_at : get ( row, "created_at" ) ?,
313318 last_active_at : get ( row, "last_active_at" ) ?,
314319 status,
@@ -322,19 +327,8 @@ fn deployment_component_detail_from_pg_row(
322327 row : & Row ,
323328) -> Result < DeploymentComponentDetail , DbErrorRead > {
324329 let component_name: String = get ( row, "component_name" ) ?;
325- let component_type: ComponentType =
326- get :: < String , _ > ( row, "component_type" ) ?
327- . parse ( )
328- . map_err ( |err| {
329- DbErrorRead :: Generic ( consistency_db_err ( format ! ( "invalid component_type: {err}" ) ) )
330- } ) ?;
331- let component_digest = ComponentDigest ( Digest (
332- get :: < Vec < u8 > , _ > ( row, "component_digest" ) ?
333- . try_into ( )
334- . map_err ( |_| {
335- DbErrorRead :: Generic ( consistency_db_err ( "invalid component_digest length" ) )
336- } ) ?,
337- ) ) ;
330+ let component_type: ComponentType = get ( row, "component_type" ) ?;
331+ let component_digest: ComponentDigest = get ( row, "component_digest" ) ?;
338332 let component_id = ComponentId :: new (
339333 component_type,
340334 StrVariant :: from ( component_name) ,
@@ -1062,24 +1056,15 @@ async fn get_combined_state(
10621056 let created_at: DateTime < Utc > = get ( & row, "created_at" ) ?;
10631057 let first_scheduled_at: DateTime < Utc > = get ( & row, "first_scheduled_at" ) ?;
10641058
1065- let digest_bytes: Vec < u8 > = get ( & row, "component_id_input_digest" ) ?;
1066- let digest = Digest :: try_from ( digest_bytes. as_slice ( ) ) . map_err ( |err| {
1067- consistency_db_err_src ( "cannot parse `component_id_input_digest`" , Arc :: from ( err) )
1068- } ) ?;
1069- let component_digest = ComponentDigest ( digest) ;
1059+ let component_digest: ComponentDigest = get ( & row, "component_id_input_digest" ) ?;
10701060
1071- let component_type: String = get ( & row, "component_type" ) ?;
1072- let component_type = ComponentType :: from_str ( & component_type)
1073- . map_err ( |err| consistency_db_err_src ( "cannot parse `component_type`" , Arc :: from ( err) ) ) ?;
1061+ let component_type: ComponentType = get ( & row, "component_type" ) ?;
10741062
10751063 let deployment_id: String = get ( & row, "deployment_id" ) ?;
10761064 let deployment_id = DeploymentId :: from_str ( & deployment_id) . map_err ( DbErrorGeneric :: from) ?;
10771065
10781066 let state: String = get ( & row, "state" ) ?;
1079- let ffqn: String = get ( & row, "ffqn" ) ?;
1080- let ffqn = FunctionFqn :: from_str ( & ffqn) . map_err ( |parse_err| {
1081- consistency_db_err ( format ! ( "invalid ffqn value in `t_state` - {parse_err}" ) )
1082- } ) ?;
1067+ let ffqn: FunctionFqn = get ( & row, "ffqn" ) ?;
10831068
10841069 let pending_expires_finished: DateTime < Utc > = get ( & row, "pending_expires_finished" ) ?;
10851070
@@ -1283,16 +1268,9 @@ async fn list_executions(
12831268 let execution_id = ExecutionId :: from_str ( & execution_id_str)
12841269 . map_err ( |err| consistency_db_err ( err. to_string ( ) ) ) ?;
12851270
1286- let digest_bytes: Vec < u8 > = get ( & row, "component_id_input_digest" ) ?;
1287- let digest = Digest :: try_from ( digest_bytes. as_slice ( ) ) . map_err ( |err| {
1288- consistency_db_err_src ( "cannot parse `component_id_input_digest`" , Arc :: from ( err) )
1289- } ) ?;
1290- let component_digest = ComponentDigest ( digest) ;
1271+ let component_digest: ComponentDigest = get ( & row, "component_id_input_digest" ) ?;
12911272
1292- let component_type: String = get ( & row, "component_type" ) ?;
1293- let component_type = ComponentType :: from_str ( & component_type) . map_err ( |err| {
1294- consistency_db_err_src ( "cannot parse `component_type`" , Arc :: from ( err) )
1295- } ) ?;
1273+ let component_type: ComponentType = get ( & row, "component_type" ) ?;
12961274
12971275 let deployment_id: String = get ( & row, "deployment_id" ) ?;
12981276 let deployment_id =
@@ -1330,11 +1308,7 @@ async fn list_executions(
13301308 . map ( |id| JoinSetId :: from_str ( & id) )
13311309 . transpose ( ) ?;
13321310
1333- let ffqn: String = get ( & row, "ffqn" ) ?;
1334- let ffqn = FunctionFqn :: from_str ( & ffqn) . map_err ( |parse_err| {
1335- error ! ( "Error parsing ffqn - {parse_err:?}" ) ;
1336- consistency_db_err ( "invalid ffqn value in `t_state`" )
1337- } ) ?;
1311+ let ffqn: FunctionFqn = get ( & row, "ffqn" ) ?;
13381312
13391313 let combined_state_dto = CombinedStateDTO {
13401314 execution_id,
@@ -1673,6 +1647,7 @@ async fn list_deployment_states(
16731647 SELECT
16741648 d.deployment_id,
16751649 d.description,
1650+ d.digest,
16761651
16771652 COUNT(*) FILTER (WHERE s.state = '{STATE_LOCKED}' AND s.is_paused = false) AS locked,
16781653
@@ -1743,7 +1718,7 @@ async fn list_deployment_states(
17431718
17441719 write ! (
17451720 sql,
1746- " GROUP BY d.deployment_id, d.description, d.config_json, d.created_at, d.last_active_at, d.status ORDER BY d.deployment_id {inner_order} LIMIT {}" ,
1721+ " GROUP BY d.deployment_id, d.description, d.digest, d. config_json, d.created_at, d.last_active_at, d.status ORDER BY d.deployment_id {inner_order} LIMIT {}" ,
17471722 pagination. length( )
17481723 )
17491724 . expect ( "writing to string" ) ;
@@ -1774,6 +1749,7 @@ async fn list_deployment_states(
17741749 result. push ( DeploymentState {
17751750 deployment_id : DeploymentId :: from_str ( & deployment_id) . map_err ( DbErrorGeneric :: from) ?,
17761751 description : get :: < Option < String > , _ > ( & row, "description" ) ?,
1752+ digest : deployment_digest_from_pg_row ( & row) ?,
17771753 locked : u32:: try_from ( get :: < i64 , _ > ( & row, "locked" ) ?) . expect ( "count is never negative" ) ,
17781754 pending : u32:: try_from ( get :: < i64 , _ > ( & row, "pending" ) ?)
17791755 . expect ( "count is never negative" ) ,
@@ -4681,18 +4657,20 @@ impl DbExternalApi for PostgresConnection {
46814657 ) ;
46824658 let mut client_guard = self . client . lock ( ) . await ;
46834659 let tx = client_guard. transaction ( ) . await ?;
4660+ let digest = record. digest . to_string ( ) ;
46844661 tx. execute (
46854662 "INSERT INTO t_deployment \
4686- (deployment_id, description, created_at, status, config_json, obelisk_version, created_by) \
4687- VALUES ($1, $2, $3, $4, $5, $6, $7)",
4663+ (deployment_id, description, digest, created_at, status, config_json, obelisk_version, created_by) \
4664+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8 )",
46884665 & [
46894666 & record. deployment_id . to_string ( ) , // $1
46904667 & record. description , // $2
4691- & record. created_at , // $3
4692- & record. status . as_str ( ) , // $4
4693- & record. config_json , // $5
4694- & record. obelisk_version , // $6
4695- & record. created_by , // $7
4668+ & digest, // $3
4669+ & record. created_at , // $4
4670+ & record. status . as_str ( ) , // $5
4671+ & record. config_json , // $6
4672+ & record. obelisk_version , // $7
4673+ & record. created_by , // $8
46964674 ] ,
46974675 )
46984676 . await ?;
@@ -4772,7 +4750,7 @@ impl DbExternalApi for PostgresConnection {
47724750 let tx = client_guard. transaction ( ) . await ?;
47734751 let row = tx
47744752 . query_opt (
4775- "SELECT deployment_id, description, created_at, last_active_at, status, config_json, obelisk_version, created_by \
4753+ "SELECT deployment_id, description, digest, created_at, last_active_at, status, config_json, obelisk_version, created_by \
47764754 FROM t_deployment WHERE deployment_id = $1",
47774755 & [ & deployment_id. to_string ( ) ] ,
47784756 )
@@ -4791,7 +4769,7 @@ impl DbExternalApi for PostgresConnection {
47914769 let tx = client_guard. transaction ( ) . await ?;
47924770 let row = tx
47934771 . query_opt (
4794- "SELECT deployment_id, description, created_at, last_active_at, status, config_json, obelisk_version, created_by \
4772+ "SELECT deployment_id, description, digest, created_at, last_active_at, status, config_json, obelisk_version, created_by \
47954773 FROM t_deployment WHERE status = 'active' LIMIT 1",
47964774 & [ ] ,
47974775 )
@@ -4808,7 +4786,7 @@ impl DbExternalApi for PostgresConnection {
48084786 let tx = client_guard. transaction ( ) . await ?;
48094787 let row = tx
48104788 . query_opt (
4811- "SELECT deployment_id, description, created_at, last_active_at, status, config_json, obelisk_version, created_by \
4789+ "SELECT deployment_id, description, digest, created_at, last_active_at, status, config_json, obelisk_version, created_by \
48124790 FROM t_deployment WHERE status IN ('enqueued', 'active') \
48134791 ORDER BY CASE status WHEN 'enqueued' THEN 0 ELSE 1 END LIMIT 1",
48144792 & [ ] ,
@@ -4835,7 +4813,7 @@ impl DbExternalApi for PostgresConnection {
48354813 } ;
48364814
48374815 let mut sql = String :: from (
4838- "SELECT deployment_id, description, created_at, last_active_at, status, config_json, obelisk_version, created_by \
4816+ "SELECT deployment_id, description, digest, created_at, last_active_at, status, config_json, obelisk_version, created_by \
48394817 FROM t_deployment",
48404818 ) ;
48414819
0 commit comments