diff --git a/.github/workflows/license_headers_check.yml b/.github/workflows/license_headers_check.yml index a909a9f8..26fe7e96 100644 --- a/.github/workflows/license_headers_check.yml +++ b/.github/workflows/license_headers_check.yml @@ -26,4 +26,5 @@ jobs: -s=only \ -ignore '.github/workflows/*.yml' \ -ignore '.github/workflows/*.yaml' \ + -ignore 'migrations/*.sql' \ . \ No newline at end of file diff --git a/.gitignore b/.gitignore index f72595b9..f222c4a4 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,4 @@ indexer.toml # IDE files .vscode/ -migrations/ +# migrations/ diff --git a/migrations/20230901142040_cost_models.down.sql b/migrations/20230901142040_cost_models.down.sql new file mode 100644 index 00000000..885eeefc --- /dev/null +++ b/migrations/20230901142040_cost_models.down.sql @@ -0,0 +1,2 @@ +-- Add down migration script here +DROP TABLE "CostModels"; diff --git a/migrations/20230901142040_cost_models.up.sql b/migrations/20230901142040_cost_models.up.sql new file mode 100644 index 00000000..96b10f0b --- /dev/null +++ b/migrations/20230901142040_cost_models.up.sql @@ -0,0 +1,8 @@ +CREATE TABLE IF NOT EXISTS "CostModels" +( + id INT, + deployment VARCHAR NOT NULL, + model TEXT, + variables JSONB, + PRIMARY KEY( deployment ) +); diff --git a/migrations/README.md b/migrations/README.md new file mode 100644 index 00000000..51b5899d --- /dev/null +++ b/migrations/README.md @@ -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` diff --git a/service/src/common/indexer_management_client/mod.rs b/service/src/common/indexer_management_client/mod.rs index 9d9575e9..bbe8ce85 100644 --- a/service/src/common/indexer_management_client/mod.rs +++ b/service/src/common/indexer_management_client/mod.rs @@ -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 { diff --git a/service/src/server/routes/cost.rs b/service/src/server/routes/cost.rs index 4b32e78f..4dab5662 100644 --- a/service/src/server/routes/cost.rs +++ b/service/src/server/routes/cost.rs @@ -11,5 +11,8 @@ pub(crate) async fn graphql_handler( Extension(schema): Extension, Extension(server_options): Extension, ) -> GraphQLResponse { - schema.execute(req.into_inner().data(server_options)).await.into() + schema + .execute(req.into_inner().data(server_options)) + .await + .into() }