Skip to content

Commit 8ef3e17

Browse files
authored
chore(postgres-sql-cmd): rename (#1147)
1 parent 5f4c2f4 commit 8ef3e17

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

examples/text_embedding/main.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from dotenv import load_dotenv
22
from psycopg_pool import ConnectionPool
33
from pgvector.psycopg import register_vector
4-
from typing import Any
54
import cocoindex
65
import os
76
import functools
@@ -72,6 +71,18 @@ def text_embedding_flow(
7271
metric=cocoindex.VectorSimilarityMetric.COSINE_SIMILARITY,
7372
)
7473
],
74+
attachments=[
75+
cocoindex.targets.PostgresSqlCommand(
76+
name="new_column_foo",
77+
setup_sql="ALTER TABLE TextEmbedding__doc_embeddings DROP COLUMN IF EXISTS foo; ALTER TABLE TextEmbedding__doc_embeddings ADD COLUMN foo TEXT",
78+
teardown_sql="ALTER TABLE TextEmbedding__doc_embeddings DROP COLUMN IF EXISTS foo",
79+
),
80+
cocoindex.targets.PostgresSqlCommand(
81+
name="new_column_bar",
82+
setup_sql="ALTER TABLE TextEmbedding__doc_embeddings ADD COLUMN bar TEXT",
83+
teardown_sql="ALTER TABLE TextEmbedding__doc_embeddings DROP COLUMN IF EXISTS bar",
84+
),
85+
],
7586
)
7687

7788

python/cocoindex/targets/_engine_builtin_specs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Postgres(op.TargetSpec):
1717
schema: str | None = None
1818

1919

20-
class PostgresSqlAttachment(op.TargetAttachmentSpec):
20+
class PostgresSqlCommand(op.TargetAttachmentSpec):
2121
"""Attachment to execute specified SQL statements for Postgres targets."""
2222

2323
name: str

src/ops/targets/postgres.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -791,26 +791,26 @@ impl TargetFactoryBase for TargetFactory {
791791
////////////////////////////////////////////////////////////
792792

793793
#[derive(Debug, Clone, Serialize, Deserialize)]
794-
pub struct SqlStatementAttachmentSpec {
794+
pub struct SqlCommandSpec {
795795
name: String,
796796
setup_sql: String,
797797
teardown_sql: Option<String>,
798798
}
799799

800800
#[derive(Debug, Clone, Serialize, Deserialize)]
801-
pub struct SqlStatementAttachmentState {
801+
pub struct SqlCommandState {
802802
setup_sql: String,
803803
teardown_sql: Option<String>,
804804
}
805805

806-
pub struct SqlStatementAttachmentSetupChange {
806+
pub struct SqlCommandSetupChange {
807807
db_pool: PgPool,
808808
setup_sql_to_run: Option<String>,
809809
teardown_sql_to_run: IndexSet<String>,
810810
}
811811

812812
#[async_trait]
813-
impl AttachmentSetupChange for SqlStatementAttachmentSetupChange {
813+
impl AttachmentSetupChange for SqlCommandSetupChange {
814814
fn describe_changes(&self) -> Vec<String> {
815815
let mut result = vec![];
816816
for teardown_sql in self.teardown_sql_to_run.iter() {
@@ -833,30 +833,30 @@ impl AttachmentSetupChange for SqlStatementAttachmentSetupChange {
833833
}
834834
}
835835

836-
struct SqlAttachmentFactory;
836+
struct SqlCommandFactory;
837837

838838
#[async_trait]
839-
impl TargetSpecificAttachmentFactoryBase for SqlAttachmentFactory {
839+
impl TargetSpecificAttachmentFactoryBase for SqlCommandFactory {
840840
type TargetKey = TableId;
841841
type TargetSpec = Spec;
842-
type Spec = SqlStatementAttachmentSpec;
842+
type Spec = SqlCommandSpec;
843843
type SetupKey = String;
844-
type SetupState = SqlStatementAttachmentState;
845-
type SetupChange = SqlStatementAttachmentSetupChange;
844+
type SetupState = SqlCommandState;
845+
type SetupChange = SqlCommandSetupChange;
846846

847847
fn name(&self) -> &str {
848-
"PostgresSqlAttachment"
848+
"PostgresSqlCommand"
849849
}
850850

851851
fn get_state(
852852
&self,
853853
_target_name: &str,
854854
_target_spec: &Spec,
855-
attachment_spec: SqlStatementAttachmentSpec,
855+
attachment_spec: SqlCommandSpec,
856856
) -> Result<TypedTargetAttachmentState<Self>> {
857857
Ok(TypedTargetAttachmentState {
858858
setup_key: attachment_spec.name,
859-
setup_state: SqlStatementAttachmentState {
859+
setup_state: SqlCommandState {
860860
setup_sql: attachment_spec.setup_sql,
861861
teardown_sql: attachment_spec.teardown_sql,
862862
},
@@ -867,10 +867,10 @@ impl TargetSpecificAttachmentFactoryBase for SqlAttachmentFactory {
867867
&self,
868868
target_key: &TableId,
869869
_attachment_key: &String,
870-
new_state: Option<SqlStatementAttachmentState>,
871-
existing_states: setup::CombinedState<SqlStatementAttachmentState>,
870+
new_state: Option<SqlCommandState>,
871+
existing_states: setup::CombinedState<SqlCommandState>,
872872
context: &interface::FlowInstanceContext,
873-
) -> Result<Option<SqlStatementAttachmentSetupChange>> {
873+
) -> Result<Option<SqlCommandSetupChange>> {
874874
let teardown_sql_to_run: IndexSet<String> = if new_state.is_none() {
875875
existing_states
876876
.possible_versions()
@@ -888,7 +888,7 @@ impl TargetSpecificAttachmentFactoryBase for SqlAttachmentFactory {
888888
};
889889
let change = if setup_sql_to_run.is_some() || !teardown_sql_to_run.is_empty() {
890890
let db_pool = get_db_pool(target_key.database.as_ref(), &context.auth_registry).await?;
891-
Some(SqlStatementAttachmentSetupChange {
891+
Some(SqlCommandSetupChange {
892892
db_pool,
893893
setup_sql_to_run,
894894
teardown_sql_to_run,
@@ -902,6 +902,6 @@ impl TargetSpecificAttachmentFactoryBase for SqlAttachmentFactory {
902902

903903
pub fn register(registry: &mut ExecutorFactoryRegistry) -> Result<()> {
904904
TargetFactory.register(registry)?;
905-
SqlAttachmentFactory.register(registry)?;
905+
SqlCommandFactory.register(registry)?;
906906
Ok(())
907907
}

0 commit comments

Comments
 (0)