Skip to content

Commit

Permalink
fix: add migration files without embedding to binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Sep 5, 2023
1 parent d8bd900 commit 12c7ef1
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/license_headers_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ jobs:
-s=only \
-ignore '.github/workflows/*.yml' \
-ignore '.github/workflows/*.yaml' \
-ignore 'migrations/*.sql' \
.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ indexer.toml

# IDE files
.vscode/
migrations/
# migrations/
2 changes: 2 additions & 0 deletions migrations/20230901142040_cost_models.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Add down migration script here
DROP TABLE "CostModels";
8 changes: 8 additions & 0 deletions migrations/20230901142040_cost_models.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE IF NOT EXISTS "CostModels"
(
id INT,
deployment VARCHAR NOT NULL,
model TEXT,
variables JSONB,
PRIMARY KEY( deployment )
);
16 changes: 16 additions & 0 deletions migrations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Database Migration setup

Indexer service binary does _NOT_ run database migrations automatically in the program binary, as it might introduce conflicts with the migrations run by indexer agent. Indexer agent is solely responsible for syncing and migrating the database.

The migration files here are included here for testing only.

### Prerequisite: Install sqlx-cli

Run `cargo install sqlx-cli --no-default-features --features native-tls,postgres`

Simple option: run general installation that supports all databases supported by SQLx
`cargo install sqlx-cli`

### Run the migration

Run `sqlx migrate run`
2 changes: 1 addition & 1 deletion service/src/common/indexer_management_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct QueryRoot;
#[derive(Debug, Clone)]
pub struct IndexerManagementClient {
database: PgPool, // Only referenced
client: Client, // it is Arc
client: Client, // it is Arc
}

impl IndexerManagementClient {
Expand Down
5 changes: 4 additions & 1 deletion service/src/server/routes/cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ pub(crate) async fn graphql_handler(
Extension(schema): Extension<CostSchema>,
Extension(server_options): Extension<ServerOptions>,
) -> GraphQLResponse {
schema.execute(req.into_inner().data(server_options)).await.into()
schema
.execute(req.into_inner().data(server_options))
.await
.into()
}

0 comments on commit 12c7ef1

Please sign in to comment.