Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/sqlbuild-analysis/src/janitor_planning/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use sqlbuild_core::constants::STATE_TABLE_NAMES;

/// SQLBuild state tables the janitor never acts on.
pub const BUILT_IN_EXCLUDE_PATTERNS: [&str; 12] = STATE_TABLE_NAMES;
pub const BUILT_IN_EXCLUDE_PATTERNS: [&str; 13] = STATE_TABLE_NAMES;
/// Prefix of every strict janitor archive name.
pub const ARCHIVE_NAME_PREFIX: &str = "_SQB_ARCHIVE__";
/// Separator between archive name segments.
Expand Down
1 change: 1 addition & 0 deletions crates/sqlbuild-cli/src/person_login/main/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ pub(crate) mod open_browser;
pub(crate) mod read_node_sql;
pub(crate) mod request_warehouse_sync;
pub(crate) mod run_login;
pub mod signed_in_principal;
pub mod sync_after_build;
22 changes: 22 additions & 0 deletions crates/sqlbuild-cli/src/person_login/main/signed_in_principal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//! The principal a person is signed in as with `sqb login`, read from local credentials only.

use std::path::Path;

use chrono::Utc;
use sqlbuild_orchestration::api::main::parse_origin::parse_origin;

use crate::person_login::_helpers::build_sync::configured_location;
use crate::person_login::_helpers::credentials;

/// `principal:<id>` of an unexpired session for the configured server; None when not signed in.
pub fn signed_in_principal(project_dir: &Path) -> Result<Option<String>, std::io::Error> {
let Some((server, _)) = configured_location(project_dir)? else {
return Ok(None);
};
let origin: String = parse_origin(&server, "CLI").map_err(std::io::Error::other)?;
let Some(credential) = credentials::load(&origin)? else {
return Ok(None);
};
Ok((credential.identity.expires_at > Utc::now())
.then(|| format!("principal:{}", credential.identity.principal_id)))
}
10 changes: 9 additions & 1 deletion crates/sqlbuild-config/src/project/_helpers/sections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::project::_helpers::values::{int_below, python_equal};
use crate::project::constants::{
ALLOW_MISSING_SECRETS_KEY, ALLOW_WAREHOUSE_ROUND_TRIPS_KEY, DEFAULT_TEST_TIMEOUT,
DEFAULT_UNIT_TEST_MAX_REAL_MODELS, DELTA_COMPILE_KEY, DISABLED_VALUE,
IGNORE_AUDIT_FAILURES_KEY, SCENARIO_TIMEOUT_KEY, TEST_TIMEOUT_KEY,
IGNORE_AUDIT_FAILURES_KEY, RECORD_RUN_HOST_KEY, SCENARIO_TIMEOUT_KEY, TEST_TIMEOUT_KEY,
UNIT_TEST_MAX_REAL_MODELS_KEY,
};
use crate::project::constants::{
Expand Down Expand Up @@ -304,6 +304,14 @@ pub(crate) fn load_settings(payload: Option<&ConfigValue>, file: ConfigFile) ->
false,
)?)),
),
(
RECORD_RUN_HOST_KEY,
Built::Value(ConfigValue::Bool(optional_bool(
mapping,
RECORD_RUN_HOST_KEY,
true,
)?)),
),
];
let mut fields = fields;
for (key, seconds_key, default) in [
Expand Down
5 changes: 4 additions & 1 deletion crates/sqlbuild-config/src/project/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ pub(crate) const ALLOW_MISSING_SECRETS_KEY: &str = "allow_missing_secrets";
pub(crate) const SCENARIO_TIMEOUT_KEY: &str = "scenario_timeout";
/// Whether a failing audit holds nothing back; `[settings]` and each target may set it.
pub(crate) const IGNORE_AUDIT_FAILURES_KEY: &str = "ignore_audit_failures";
/// Whether each run records the machine it ran on in the runs state table.
pub(crate) const RECORD_RUN_HOST_KEY: &str = "record_run_host";
pub(crate) const DEFAULT_TEST_TIMEOUT: &str = "30s";
pub(crate) const SETTINGS_KEYS: [&str; 18] = [
pub(crate) const SETTINGS_KEYS: [&str; 19] = [
"sql_analysis",
"require_sql_analysis",
"query_change_tracking",
Expand All @@ -75,6 +77,7 @@ pub(crate) const SETTINGS_KEYS: [&str; 18] = [
"allow_missing_secrets",
"allow_warehouse_round_trips",
IGNORE_AUDIT_FAILURES_KEY,
RECORD_RUN_HOST_KEY,
];
pub(crate) const DEFAULTS_KEYS: [&str; 33] = [
"append_cursor_inclusive",
Expand Down
9 changes: 6 additions & 3 deletions crates/sqlbuild-core/src/build_command/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ pub(crate) const C0_CONTROL_CODE_LIMIT: u32 = 0x20;
pub(crate) const C1_CONTROL_CODE_START: u32 = 0x7f;
pub(crate) const C1_CONTROL_CODE_LIMIT: u32 = 0xa0;

pub(crate) const PYTHON_NODE_SUCCESS: &str = "success";
pub(crate) const PYTHON_NODE_SKIPPED: &str = "skipped";
pub(crate) const PYTHON_NODE_FAILED: &str = "failed";
/// A Python node or check that succeeded, warnings included.
pub const PYTHON_NODE_SUCCESS: &str = "success";
/// A Python node or check that never ran.
pub const PYTHON_NODE_SKIPPED: &str = "skipped";
/// A Python node or check that failed, which fails the build.
pub const PYTHON_NODE_FAILED: &str = "failed";
pub(crate) const PYTHON_STATUS_OK: &str = "OK";
pub(crate) const PYTHON_STATUS_SKIP: &str = "SKIP";
pub(crate) const PYTHON_STATUS_FAIL: &str = "FAIL";
Expand Down
5 changes: 4 additions & 1 deletion crates/sqlbuild-core/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ pub const JANITOR_EVENTS_TABLE_NAME: &str = "_sqlbuild_janitor_events";
pub const OBSERVATIONS_TABLE_NAME: &str = "_sqlbuild_observations";
/// State table of estimated query cost per run, resource and warehouse; display only.
pub const RESOURCE_COSTS_TABLE_NAME: &str = "_sqlbuild_resource_costs";
/// State table of each build's start and end, which shows runs the control plane did not start.
pub const RUNS_TABLE_NAME: &str = "_sqlbuild_runs";
/// Every state table SQLBuild writes in a target's state schema.
pub const STATE_TABLE_NAMES: [&str; 12] = [
pub const STATE_TABLE_NAMES: [&str; 13] = [
FINGERPRINT_TABLE_NAME,
MICROBATCH_TABLE_NAME,
SOURCE_FRESHNESS_TABLE_NAME,
Expand All @@ -56,6 +58,7 @@ pub const STATE_TABLE_NAMES: [&str; 12] = [
OLD_NAME_VIEW_TABLE_NAME,
OBSERVATIONS_TABLE_NAME,
RESOURCE_COSTS_TABLE_NAME,
RUNS_TABLE_NAME,
];
/// A zero-length cursor duration.
pub const ZERO_DAY_DURATION: &str = "0d";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use chrono::{DateTime, Duration, Utc};
use reqwest::StatusCode;
use serde_json::json;
use sqlbuild_core::constants::STATE_TABLE_NAMES;
use sqlbuild_core::constants::{RUNS_TABLE_NAME, STATE_TABLE_NAMES};
use uuid::Uuid;

use crate::api::tests::changes_helpers::{connect, expect_topics};
Expand Down Expand Up @@ -36,7 +36,11 @@ use crate::warehouse_metadata::models::{MetadataBatch, WarehouseHistoryKind};

#[test]
fn given_state_tables_when_classified_then_each_is_mirrored_by_exactly_one_kind() {
let mut written: Vec<&str> = STATE_TABLE_NAMES.to_vec();
// The runs table has no mirror until the control store decides where observed runs live.
let mut written: Vec<&str> = STATE_TABLE_NAMES
.into_iter()
.filter(|table| *table != RUNS_TABLE_NAME)
.collect();
written.sort_unstable();
let test_cases = [StateTableClassificationTestCase {
description: "every state table SQLBuild writes, with statistics rewinding to catalog",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ const R_SETTINGS_CONFIG: RecordSpec = RecordSpec {
FieldSpec::new("allow_missing_secrets", FieldDefault::False),
FieldSpec::new("allow_warehouse_round_trips", FieldDefault::False),
FieldSpec::new("ignore_audit_failures", FieldDefault::False),
FieldSpec::new("record_run_host", FieldDefault::True),
],
};
const R_SCOPES_CONFIG: RecordSpec = RecordSpec {
Expand Down
2 changes: 2 additions & 0 deletions crates/sqlbuild-python-project/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ rust-version.workspace = true
chrono.workspace = true
chrono-tz.workspace = true
pyo3.workspace = true
serde.workspace = true
serde_json.workspace = true
sha2.workspace = true
sqlbuild-analysis.workspace = true
Expand All @@ -30,6 +31,7 @@ sqlbuild-python-base.workspace = true
sqlbuild-python-front.workspace = true
sqlbuild-rules.workspace = true
sqlbuild-sqltext.workspace = true
sqlbuild-state.workspace = true
tokio.workspace = true
uuid.workspace = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,15 @@ pub(crate) fn selected_jobs(
selectors: &[String],
catalog: &BTreeMap<String, JobSelection>,
) -> BTreeSet<String> {
let mut jobs: BTreeSet<String> = BTreeSet::new();
ordered_jobs(selectors, catalog).into_iter().collect()
}

/// The jobs `selectors` name, each once in the order first named.
pub(crate) fn ordered_jobs(
selectors: &[String],
catalog: &BTreeMap<String, JobSelection>,
) -> Vec<String> {
let mut jobs: Vec<String> = Vec::new();
let parts = selectors
.iter()
.flat_map(|selector| selector.split(char::is_whitespace))
Expand All @@ -63,8 +71,11 @@ pub(crate) fn selected_jobs(
let Ok(ParsedSelector::Kind { kind, value, .. }) = parse_selector(part) else {
continue;
};
if JOB_SELECTOR_KINDS.contains(&kind.as_str()) && catalog.contains_key(&value) {
jobs.insert(value);
if JOB_SELECTOR_KINDS.contains(&kind.as_str())
&& catalog.contains_key(&value)
&& !jobs.contains(&value)
{
jobs.push(value);
}
}
jobs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod install;
pub mod job_names;
pub mod materialization;
pub mod model_facts;
pub mod named_jobs;
pub mod needed_jobs;
pub mod plain_value;
pub mod python_column_fact;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! The jobs a command's selectors name, in the order named.

use crate::compiled_project::_helpers::job_catalog::job_catalog;
use crate::compiled_project::_helpers::job_catalog::ordered_jobs;
use pyo3::prelude::{PyResult, Python};

/// The jobs `selectors` name, as `job:<name>` or a bare job name, each once in the order named; none outside a command.
pub fn named_jobs(py: Python<'_>, selectors: &[String]) -> PyResult<Vec<String>> {
Ok(job_catalog(py)?
.map(|(catalog, _)| ordered_jobs(selectors, &catalog))
.unwrap_or_default())
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub(crate) mod orchestration_triggers;
pub(crate) mod runs_state;
Loading
Loading