diff --git a/.github/workflows/estore.yaml b/.github/workflows/estore.yaml index 68653c2..6606da6 100644 --- a/.github/workflows/estore.yaml +++ b/.github/workflows/estore.yaml @@ -1,16 +1,17 @@ -name: Setup Atlas - +name: EStore Inventory Pipeline on: push: branches: - master pull_request: - branches: - - master - +permissions: + contents: read + pull-requests: write jobs: setup: runs-on: ubuntu-latest + env: + GITHUB_TOKEN: ${{ github.token }} steps: - name: Checkout code uses: actions/checkout@v4 @@ -18,6 +19,13 @@ jobs: uses: ariga/setup-atlas@v0 with: cloud-token: ${{ secrets.ATLAS_PUBLIC_TENANT_TOKEN }} + - name: Lint Migrations + uses: ariga/atlas-action/migrate/lint@v1 + with: + dir-name: 'estore-inventory' + dir: 'file://projects/estore/inventory/migrations' + env: 'local' + config: 'file://projects/estore/atlas.hcl' - name: Push to Registry if: github.ref == 'refs/heads/master' uses: ariga/atlas-action/migrate/push@v1 diff --git a/projects/estore/inventory/migrations/20240307104354_add_warehouses.sql b/projects/estore/inventory/migrations/20240307104354_add_warehouses.sql new file mode 100644 index 0000000..90cd35b --- /dev/null +++ b/projects/estore/inventory/migrations/20240307104354_add_warehouses.sql @@ -0,0 +1,16 @@ +-- Create "regions" table +CREATE TABLE `regions` ( + `region_id` int NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + PRIMARY KEY (`region_id`) +) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci; +-- Create "warehouses" table +CREATE TABLE `warehouses` ( + `warehouse_id` int NOT NULL AUTO_INCREMENT, + `name` varchar(255) NOT NULL, + `address` text NOT NULL, + `region_id` int NULL, + PRIMARY KEY (`warehouse_id`), + INDEX `region_id` (`region_id`), + CONSTRAINT `warehouses_ibfk_1` FOREIGN KEY (`region_id`) REFERENCES `regions` (`region_id`) ON UPDATE NO ACTION ON DELETE NO ACTION +) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci; diff --git a/projects/estore/inventory/migrations/atlas.sum b/projects/estore/inventory/migrations/atlas.sum index fba196e..6e7cf79 100644 --- a/projects/estore/inventory/migrations/atlas.sum +++ b/projects/estore/inventory/migrations/atlas.sum @@ -1,2 +1,3 @@ -h1:fo2R2MvvR2SDqpcg3lMGjPvOwppIJ3AIR7rtGh5zPpU= +h1:OD80uv7vCyCGr2x6dS4rLVaCkoj7JyydbcT6gxQAShI= 20240307092728.sql h1:BEXRAbglZQlUqXHRy4fvsEVsu7FlSfKcJ/JAkH2XgMY= +20240307104354_add_warehouses.sql h1:heT56DSu6Ka8TJo8K4F92rVxinZmt+7tbMX+y3vaJKo= diff --git a/projects/estore/inventory/schema.hcl b/projects/estore/inventory/schema.hcl index 24b5a14..ede22d2 100644 --- a/projects/estore/inventory/schema.hcl +++ b/projects/estore/inventory/schema.hcl @@ -67,6 +67,21 @@ table "products" { columns = [column.supplier_id] } } +table "regions" { + schema = schema.default + column "region_id" { + null = false + type = int + auto_increment = true + } + column "name" { + null = false + type = varchar(255) + } + primary_key { + columns = [column.region_id] + } +} table "suppliers" { schema = schema.default column "supplier_id" { @@ -86,6 +101,38 @@ table "suppliers" { columns = [column.supplier_id] } } +table "warehouses" { + schema = schema.default + column "warehouse_id" { + null = false + type = int + auto_increment = true + } + column "name" { + null = false + type = varchar(255) + } + column "address" { + null = false + type = text + } + column "region_id" { + null = true + type = int + } + primary_key { + columns = [column.warehouse_id] + } + foreign_key "warehouses_ibfk_1" { + columns = [column.region_id] + ref_columns = [table.regions.column.region_id] + on_update = NO_ACTION + on_delete = NO_ACTION + } + index "region_id" { + columns = [column.region_id] + } +} schema "default" { charset = "utf8mb4" collate = "utf8mb4_0900_ai_ci"