|
Pharos 0.7.23
Modern Web Framework & Web App Hosting Service.
|
Verifies sqlite migration state natively and emits structured migration verification reports. More...
#include "native_migrate_verify.h"#include "native_artifact_emit.h"#include "native_json_config.h"#include "native_process_capture.h"#include "native_support.h"#include "native_yyjson_helpers.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/wait.h>#include <unistd.h>Go to the source code of this file.
Macros | |
| #define | native_migrate_verify_strdup strdup |
Functions | |
| static char * | native_json_literal_dup (const char *value) |
| Duplicates a static JSON literal string. | |
| static char * | native_json_nullable_string_dup (const char *value) |
| Duplicates a string value as JSON string text, or null when absent. | |
| static char * | native_json_value_or_literal_dup (yyjson_val *value, const char *fallback) |
| Duplicates a borrowed JSON value as compact JSON, or a fallback literal. | |
| static char * | native_json_object_string_json_dup (yyjson_val *obj, const char *key, const char *fallback) |
| Duplicates an object string field as JSON string text with a default. | |
| static char * | native_long_json_dup (long value) |
| Converts a long value to owned JSON number text. | |
| static int | native_identifier_safe (const char *value) |
| Tests whether a string is a safe sqlite identifier. | |
| static char * | native_resolve_command_path (const char *command) |
| Resolves an executable from PATH. | |
| static int | native_command_exists (const char *command) |
| Tests whether a required native tool is available. | |
| static char * | native_capture_trimmed (char *const argv[], int *code_out) |
| Runs a subprocess and trims surrounding whitespace from stdout. | |
| static int | native_append_escaped_sql_char (Buffer *buffer, char value) |
| Appends one SQL character with sqlite literal escaping. | |
| static char * | native_sql_literal_escape (const char *value) |
| Escapes a string for safe inclusion in a sqlite string literal. | |
| static int | native_write_temp_text_file (const char *text, char **path_out) |
| Writes temporary text content to a file. | |
| static char * | native_capture_checksum_output (const char *command, const char *arg1, const char *arg2, const char *file_path, int *code_out) |
| Captures checksum tool output for a temporary file. | |
| static int | native_seed_expectation_satisfied (long row_count, int minimum_present, long minimum_rows, int exact_present, long exact_rows, const char **reason_out) |
| Evaluates whether a seed expectation passes. | |
| static int | native_json_string_array_contains (yyjson_val *array_value, const char *expected_value) |
| Tests whether a JSON string array contains one exact string. | |
| static int | native_migration_checksum_matches (int applied, const char *applied_checksum, const char *expected_checksum, const char *legacy_expected_checksum, yyjson_val *accepted_legacy_checksums) |
| Tests whether an applied checksum satisfies expected checksum contracts. | |
| static char * | native_sqlite_query_value (const char *db_path, const char *sql) |
| Executes a sqlite query and captures one trimmed stdout value. | |
| static int | native_sqlite_table_exists (const char *db_path, const char *table_name) |
| Tests whether a sqlite table exists. | |
| static long | native_sqlite_table_row_count (const char *db_path, const char *table_name) |
| Counts rows in a sqlite table. | |
| static long | native_sqlite_migration_applied_count (const char *db_path, const char *migration_id, const char *backend) |
| Counts applied migration ledger rows. | |
| static char * | native_sqlite_migration_applied_schema_version (const char *db_path, const char *migration_id, const char *backend) |
| Reads the applied schema version for a migration. | |
| static char * | native_sqlite_migration_applied_checksum (const char *db_path, const char *migration_id, const char *backend) |
| Reads the applied checksum for a migration. | |
| static int | native_append_file_to_buffer (Buffer *buffer, const char *file_path) |
| Appends a whole file to a growable buffer followed by a newline. | |
| static int | native_append_path_marker (Buffer *buffer, const char *file_path) |
| Appends a path marker line to a checksum input buffer. | |
| static char * | native_checksum_string (const char *value) |
| Computes a sha256 checksum string for arbitrary text. | |
| static char * | native_resolve_app_path (const char *app_root, const char *value) |
| Resolves a path string relative to the app root when needed. | |
| static int | native_append_seed_sources_to_buffer (Buffer *buffer, const char *app_root, yyjson_val *seed_sources) |
| Appends resolved seed source files into a checksum buffer. | |
| static char * | native_append_json_item (Buffer *buffer, const char *json_item, int *first) |
| Appends a JSON array item into a buffer-backed array literal. | |
| static int | native_append_json_string_item (Buffer *buffer, const char *value, int *first) |
| Appends a JSON string item into a buffer-backed array literal. | |
| static char * | native_finish_json_array (Buffer *buffer, int first) |
| Finalizes a buffer-backed JSON array literal. | |
| static int | native_append_forward_sql_bundle (Buffer *combined, const char *app_root, yyjson_val *migration_record, const char *backend) |
| Appends forward SQL file contents for one migration/backend pair. | |
| static char * | native_expected_migration_checksum (const char *app_root, yyjson_val *migration_record, const char *entity_fixture, const char *query_fixture, const char *backend) |
| Computes the current expected checksum for a migration. | |
| static char * | native_legacy_expected_migration_checksum (const char *app_root, yyjson_val *migration_record, const char *entity_fixture, const char *query_fixture, const char *backend, yyjson_val *seed_sources) |
| Computes the legacy expected checksum for a migration. | |
| static char * | native_default_sqlite_path (const AppRuntime *app) |
| Returns the default sqlite path for an app. | |
| char * | native_capture_migrate_verify_sqlite_report_json (const ServeConfig *config, const AppRuntime *app, char **status_out, char **error_out) |
| Captures a sqlite migration verification report for one app. | |
Verifies sqlite migration state natively and emits structured migration verification reports.
Definition in file native_migrate_verify.c.
| #define native_migrate_verify_strdup strdup |
Definition at line 22 of file native_migrate_verify.c.
Referenced by native_capture_migrate_verify_sqlite_report_json(), native_default_sqlite_path(), native_finish_json_array(), native_json_literal_dup(), native_long_json_dup(), native_resolve_command_path(), and native_write_temp_text_file().
|
static |
Appends one SQL character with sqlite literal escaping.
| buffer | Destination buffer. |
| value | Character to append. |
Definition at line 191 of file native_migrate_verify.c.
References buffer_append().
Referenced by native_sql_literal_escape().
|
static |
Appends a whole file to a growable buffer followed by a newline.
| buffer | Destination buffer. |
| file_path | File path to append. |
Definition at line 590 of file native_migrate_verify.c.
References buffer_append(), and read_file_text().
Referenced by native_append_forward_sql_bundle(), native_append_seed_sources_to_buffer(), and native_expected_migration_checksum().
|
static |
Appends forward SQL file contents for one migration/backend pair.
| combined | Destination checksum input buffer. |
| app_root | App root directory. |
| migration_record | Migration object. |
| backend | Backend name. |
Definition at line 791 of file native_migrate_verify.c.
References native_append_file_to_buffer(), native_append_path_marker(), native_json_obj_get(), native_json_obj_get_array(), native_resolve_app_path(), yyjson_arr_iter_init(), yyjson_arr_iter_next(), yyjson_get_str(), and yyjson_is_str().
Referenced by native_expected_migration_checksum().
|
static |
Appends a JSON array item into a buffer-backed array literal.
| buffer | Destination buffer. |
| json_item | Already serialized JSON item. |
| first | Tracks whether the array already has an item. |
Definition at line 724 of file native_migrate_verify.c.
References buffer_append(), Buffer::data, and Buffer::len.
Referenced by native_append_json_string_item(), and native_capture_migrate_verify_sqlite_report_json().
|
static |
Appends a JSON string item into a buffer-backed array literal.
| buffer | Destination buffer. |
| value | Plain string value. |
| first | Tracks whether the array already has an item. |
Definition at line 751 of file native_migrate_verify.c.
References json_string_dup_native(), and native_append_json_item().
Referenced by native_capture_migrate_verify_sqlite_report_json().
|
static |
Appends a path marker line to a checksum input buffer.
| buffer | Destination buffer. |
| file_path | Source file path. |
Definition at line 610 of file native_migrate_verify.c.
References buffer_append().
Referenced by native_append_forward_sql_bundle(), and native_append_seed_sources_to_buffer().
|
static |
Appends resolved seed source files into a checksum buffer.
| buffer | Destination buffer. |
| app_root | App root used for relative seed paths. |
| seed_sources | Array of seed source paths. |
Definition at line 680 of file native_migrate_verify.c.
References native_append_file_to_buffer(), native_append_path_marker(), native_resolve_app_path(), path_exists(), yyjson_arr_iter_init(), yyjson_arr_iter_next(), yyjson_get_str(), yyjson_is_arr(), and yyjson_is_str().
Referenced by native_legacy_expected_migration_checksum().
|
static |
Captures checksum tool output for a temporary file.
| command | Checksum command. |
| arg1 | Optional first flag. |
| arg2 | Optional second flag. |
| file_path | File to checksum. |
| code_out | Optional exit code output. |
Definition at line 273 of file native_migrate_verify.c.
References native_capture_trimmed(), and native_resolve_command_path().
Referenced by native_checksum_string().
| char * native_capture_migrate_verify_sqlite_report_json | ( | const ServeConfig * | config, |
| const AppRuntime * | app, | ||
| char ** | status_out, | ||
| char ** | error_out ) |
Captures a sqlite migration verification report for one app.
| config | Active serve configuration. |
| app | Finalized app runtime to verify. |
| status_out | Optional destination for an allocated verification status string. |
| error_out | Optional destination for an allocated error message. |
Definition at line 998 of file native_migrate_verify.c.
References AppRuntime::app_id, AppRuntime::app_root, buffer_free(), buffer_init(), Buffer::data, json_string_dup_native(), native_append_json_item(), native_append_json_string_item(), native_command_exists(), native_default_sqlite_path(), native_expected_migration_checksum(), native_finish_json_array(), native_json_doc_free(), native_json_doc_load_file(), native_json_find_backend_by_name(), native_json_find_migration_by_id(), native_json_literal_dup(), native_json_nullable_string_dup(), native_json_obj_get(), native_json_obj_get_array(), native_json_obj_get_long_default(), native_json_obj_get_string_dup(), native_json_object_string_json_dup(), native_json_value_or_literal_dup(), native_legacy_expected_migration_checksum(), native_long_json_dup(), native_migrate_verify_strdup, native_migration_checksum_matches(), native_resolve_app_path(), native_seed_expectation_satisfied(), native_sqlite_migration_applied_checksum(), native_sqlite_migration_applied_count(), native_sqlite_migration_applied_schema_version(), native_sqlite_table_exists(), native_sqlite_table_row_count(), path_exists(), path_join(), streq(), ServeConfig::target_id, yyjson_arr_iter_init(), yyjson_arr_iter_next(), yyjson_doc_get_root(), yyjson_get_str(), yyjson_is_obj(), and yyjson_is_str().
Referenced by capture_migrate_verify_report_json().
|
static |
Runs a subprocess and trims surrounding whitespace from stdout.
| argv | Command argv vector. |
| code_out | Optional process exit code output. |
Definition at line 173 of file native_migrate_verify.c.
References run_process_capture_native(), and trim_in_place().
Referenced by native_capture_checksum_output(), and native_sqlite_query_value().
|
static |
Computes a sha256 checksum string for arbitrary text.
| value | Input text. |
Definition at line 624 of file native_migrate_verify.c.
References native_capture_checksum_output(), native_command_exists(), and native_write_temp_text_file().
Referenced by native_expected_migration_checksum(), and native_legacy_expected_migration_checksum().
|
static |
Tests whether a required native tool is available.
| command | Command to resolve. |
Definition at line 160 of file native_migrate_verify.c.
References native_resolve_command_path().
Referenced by native_capture_migrate_verify_sqlite_report_json(), and native_checksum_string().
|
static |
Returns the default sqlite path for an app.
| app | App runtime. |
Definition at line 985 of file native_migrate_verify.c.
References AppRuntime::app_id, conf_lookup_value(), native_migrate_verify_strdup, and AppRuntime::runtime_conf_path.
Referenced by native_capture_migrate_verify_sqlite_report_json().
|
static |
Computes the current expected checksum for a migration.
| app_root | App root directory. |
| migration_record | Migration object. |
| entity_fixture | Optional entity fixture path. |
| query_fixture | Optional query fixture path. |
| backend | Backend name. |
Definition at line 843 of file native_migrate_verify.c.
References buffer_free(), buffer_init(), Buffer::data, native_append_file_to_buffer(), native_append_forward_sql_bundle(), native_checksum_string(), and path_exists().
Referenced by native_capture_migrate_verify_sqlite_report_json(), and native_legacy_expected_migration_checksum().
|
static |
Finalizes a buffer-backed JSON array literal.
| buffer | Array buffer. |
| first | Whether no items were appended. |
Definition at line 769 of file native_migrate_verify.c.
References buffer_append(), buffer_free(), Buffer::data, and native_migrate_verify_strdup.
Referenced by native_capture_migrate_verify_sqlite_report_json().
|
static |
Tests whether a string is a safe sqlite identifier.
| value | Candidate identifier. |
Definition at line 96 of file native_migrate_verify.c.
Referenced by native_sqlite_table_exists(), and native_sqlite_table_row_count().
|
static |
Duplicates a static JSON literal string.
| value | JSON literal text to duplicate. |
Definition at line 29 of file native_migrate_verify.c.
References native_migrate_verify_strdup.
Referenced by native_capture_migrate_verify_sqlite_report_json(), native_json_nullable_string_dup(), and native_json_value_or_literal_dup().
|
static |
Duplicates a string value as JSON string text, or null when absent.
| value | Source string. |
Definition at line 38 of file native_migrate_verify.c.
References json_string_dup_native(), and native_json_literal_dup().
Referenced by native_capture_migrate_verify_sqlite_report_json().
|
static |
Duplicates an object string field as JSON string text with a default.
| obj | Object to inspect. |
| key | Field name. |
| fallback | Default plain string value. |
Definition at line 67 of file native_migrate_verify.c.
References json_string_dup_native(), and native_json_obj_get_string_dup().
Referenced by native_capture_migrate_verify_sqlite_report_json().
|
static |
Tests whether a JSON string array contains one exact string.
| array_value | Array to inspect. |
| expected_value | Expected string. |
Definition at line 340 of file native_migrate_verify.c.
References yyjson_arr_iter_init(), yyjson_arr_iter_next(), yyjson_equals_str(), yyjson_is_arr(), and yyjson_is_str().
Referenced by native_legacy_expected_migration_checksum(), and native_migration_checksum_matches().
|
static |
Duplicates a borrowed JSON value as compact JSON, or a fallback literal.
| value | Borrowed JSON value. |
| fallback | Fallback JSON literal. |
Definition at line 51 of file native_migrate_verify.c.
References native_json_literal_dup(), and native_json_serialize_compact_dup().
Referenced by native_capture_migrate_verify_sqlite_report_json().
|
static |
Computes the legacy expected checksum for a migration.
| app_root | App root directory. |
| migration_record | Migration object. |
| entity_fixture | Optional entity fixture path. |
| query_fixture | Optional query fixture path. |
| backend | Backend name. |
| seed_sources | Resolved seed source array. |
Definition at line 883 of file native_migrate_verify.c.
References buffer_append(), buffer_free(), buffer_init(), Buffer::data, native_append_seed_sources_to_buffer(), native_checksum_string(), native_expected_migration_checksum(), native_json_obj_get_array(), native_json_obj_get_string_dup(), native_json_string_array_contains(), path_exists(), and read_file_text().
Referenced by native_capture_migrate_verify_sqlite_report_json().
|
static |
Converts a long value to owned JSON number text.
| value | Numeric value to serialize. |
Definition at line 85 of file native_migrate_verify.c.
References native_migrate_verify_strdup.
Referenced by native_capture_migrate_verify_sqlite_report_json().
|
static |
Tests whether an applied checksum satisfies expected checksum contracts.
| applied | Whether the migration is applied. |
| applied_checksum | Applied checksum text. |
| expected_checksum | Primary expected checksum. |
| legacy_expected_checksum | Legacy expected checksum. |
| accepted_legacy_checksums | Array of accepted legacy checksums. |
Definition at line 368 of file native_migrate_verify.c.
References native_json_string_array_contains(), and streq().
Referenced by native_capture_migrate_verify_sqlite_report_json().
|
static |
Resolves a path string relative to the app root when needed.
| app_root | App root directory. |
| value | Raw path value. |
Definition at line 669 of file native_migrate_verify.c.
References resolve_relative_to().
Referenced by native_append_forward_sql_bundle(), native_append_seed_sources_to_buffer(), and native_capture_migrate_verify_sqlite_report_json().
|
static |
Resolves an executable from PATH.
| command | Command name or path. |
Definition at line 117 of file native_migrate_verify.c.
References native_migrate_verify_strdup.
Referenced by native_capture_checksum_output(), native_command_exists(), and native_sqlite_query_value().
|
static |
Evaluates whether a seed expectation passes.
| row_count | Observed row count. |
| minimum_present | Whether minimum_rows was provided. |
| minimum_rows | Minimum row threshold. |
| exact_present | Whether exact_rows was provided. |
| exact_rows | Exact row requirement. |
| reason_out | Receives the failure reason. |
Definition at line 313 of file native_migrate_verify.c.
Referenced by native_capture_migrate_verify_sqlite_report_json().
|
static |
Escapes a string for safe inclusion in a sqlite string literal.
| value | Input string. |
Definition at line 208 of file native_migrate_verify.c.
References buffer_free(), buffer_init(), Buffer::data, and native_append_escaped_sql_char().
Referenced by native_sqlite_migration_applied_checksum(), native_sqlite_migration_applied_count(), native_sqlite_migration_applied_schema_version(), and native_sqlite_table_exists().
|
static |
Reads the applied checksum for a migration.
| db_path | Database path. |
| migration_id | Migration id. |
| backend | Backend name. |
Definition at line 556 of file native_migrate_verify.c.
References native_sql_literal_escape(), and native_sqlite_query_value().
Referenced by native_capture_migrate_verify_sqlite_report_json().
|
static |
Counts applied migration ledger rows.
| db_path | Database path. |
| migration_id | Migration id. |
| backend | Backend name. |
Definition at line 481 of file native_migrate_verify.c.
References native_sql_literal_escape(), and native_sqlite_query_value().
Referenced by native_capture_migrate_verify_sqlite_report_json().
|
static |
Reads the applied schema version for a migration.
| db_path | Database path. |
| migration_id | Migration id. |
| backend | Backend name. |
Definition at line 520 of file native_migrate_verify.c.
References native_sql_literal_escape(), and native_sqlite_query_value().
Referenced by native_capture_migrate_verify_sqlite_report_json().
|
static |
Executes a sqlite query and captures one trimmed stdout value.
| db_path | Database path. |
| sql | SQL statement. |
Definition at line 394 of file native_migrate_verify.c.
References native_capture_trimmed(), and native_resolve_command_path().
Referenced by native_sqlite_migration_applied_checksum(), native_sqlite_migration_applied_count(), native_sqlite_migration_applied_schema_version(), native_sqlite_table_exists(), and native_sqlite_table_row_count().
|
static |
Tests whether a sqlite table exists.
| db_path | Database path. |
| table_name | Table name. |
Definition at line 425 of file native_migrate_verify.c.
References native_identifier_safe(), native_sql_literal_escape(), native_sqlite_query_value(), and streq().
Referenced by native_capture_migrate_verify_sqlite_report_json().
|
static |
Counts rows in a sqlite table.
| db_path | Database path. |
| table_name | Table name. |
Definition at line 457 of file native_migrate_verify.c.
References native_identifier_safe(), and native_sqlite_query_value().
Referenced by native_capture_migrate_verify_sqlite_report_json().
|
static |
Writes temporary text content to a file.
| text | Text payload. |
| path_out | Receives the created path. |
Definition at line 228 of file native_migrate_verify.c.
References native_migrate_verify_strdup.
Referenced by native_checksum_string().