-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
377 additions
and
48 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
api/.sqlx/query-4f38f0fd1e56661000bde2c712331fff08af722f932f5ccd4a9083b99bcaf8d8.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 3 additions & 2 deletions
5
...b72fc186de50dafd5a90149ee2d1b501ccfe.json → ...d5575357b71a8008344c3e6ae86b8e622bd5.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
13 changes: 9 additions & 4 deletions
13
...272d8edc1414e7cb44f56d5965c93fcaba9d.json → ...1b944268727c84ae8a02cfc7c15fdf49a5d3.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
13 changes: 10 additions & 3 deletions
13
...efe3340bce3a6e6a18fd84716a61e3ab20c2.json → ...1020bd26a5f21a9a27b6eb580ea730a0e3dd.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
api/.sqlx/query-c3a6dc4b4f1e478d6b9a142328b0de91c8ad174fa2bb7b0c217e843aa6f1cde2.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
create type replicator_status as enum ('stopped', 'starting', 'started', 'stopping'); | ||
|
||
create table | ||
public.replicators ( | ||
id bigint generated always as identity primary key, | ||
tenant_id bigint references public.tenants(id) not null, | ||
status replicator_status not null | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod pipelines; | ||
pub mod publications; | ||
pub mod replicators; | ||
pub mod sinks; | ||
pub mod sources; | ||
pub mod tables; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use sqlx::{PgPool, Postgres, Transaction}; | ||
|
||
#[derive(Clone, Debug, PartialEq, PartialOrd, sqlx::Type)] | ||
#[sqlx(type_name = "replicator_status", rename_all = "lowercase")] | ||
pub enum ReplicatorStatus { | ||
Stopped, | ||
Starting, | ||
Started, | ||
Stopping, | ||
} | ||
|
||
pub struct Replicator { | ||
pub id: i64, | ||
pub tenant_id: i64, | ||
pub status: ReplicatorStatus, | ||
} | ||
|
||
pub async fn create_replicator(pool: &PgPool, tenant_id: i64) -> Result<i64, sqlx::Error> { | ||
let mut txn = pool.begin().await?; | ||
let res = create_replicator_txn(&mut txn, tenant_id).await; | ||
txn.commit().await?; | ||
res | ||
} | ||
|
||
pub async fn create_replicator_txn( | ||
txn: &mut Transaction<'_, Postgres>, | ||
tenant_id: i64, | ||
) -> Result<i64, sqlx::Error> { | ||
let record = sqlx::query!( | ||
r#" | ||
insert into replicators (tenant_id, status) | ||
values ($1, $2::replicator_status) | ||
returning id | ||
"#, | ||
tenant_id, | ||
ReplicatorStatus::Stopped as ReplicatorStatus | ||
) | ||
.fetch_one(&mut **txn) | ||
.await?; | ||
|
||
Ok(record.id) | ||
} | ||
|
||
pub async fn read_replicator_by_pipeline_id( | ||
pool: &PgPool, | ||
tenant_id: i64, | ||
pipeline_id: i64, | ||
) -> Result<Option<Replicator>, sqlx::Error> { | ||
let record = sqlx::query!( | ||
r#" | ||
select r.id, r.tenant_id, status as "status: ReplicatorStatus" | ||
from replicators r | ||
join pipelines p on r.id = p.replicator_id | ||
where r.tenant_id = $1 and p.tenant_id = $1 and p.id = $2 | ||
"#, | ||
tenant_id, | ||
pipeline_id, | ||
) | ||
.fetch_optional(pool) | ||
.await?; | ||
|
||
Ok(record.map(|r| Replicator { | ||
id: r.id, | ||
tenant_id: r.tenant_id, | ||
status: r.status, | ||
})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.