diff --git a/.github/workflows/atlas-ci.yml b/.github/workflows/atlas-ci.yml index 954f0e5..962069c 100644 --- a/.github/workflows/atlas-ci.yml +++ b/.github/workflows/atlas-ci.yml @@ -1,83 +1,44 @@ name: Atlas on: push: - branches: [ main ] + branches: + - main + paths: + - .github/workflows/ci-atlas.yaml + - 'migrations/*' pull_request: - branches: [ main ] - workflow_dispatch: + paths: + - 'migrations/*' # Permissions to write comments on the pull request. permissions: contents: read pull-requests: write jobs: - plan: - if: ${{ github.event_name == 'pull_request' }} - services: - # Spin up a postgres:15 container to be used as the dev-database for analysis. - postgres: - image: postgres:15 - env: - POSTGRES_DB: dev - POSTGRES_PASSWORD: pass - ports: - - 5432:5432 - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-start-period 10s - --health-timeout 5s - --health-retries 5 + atlas: runs-on: ubuntu-latest - env: - GITHUB_TOKEN: ${{ github.token }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - uses: ariga/setup-atlas@v0 with: - cloud-token: ${{ secrets.ATLAS_CLOUD_TOKEN }} - - uses: ariga/atlas-action/schema/plan@v1 + cloud-token: '${{ secrets.ATLAS_CLOUD_TOKEN }}' + version: 'beta' + - uses: ariga/atlas-action/migrate/lint@v1 with: - env: ci - dev-url: 'postgres://postgres:pass@localhost:5432/dev?search_path=public&sslmode=disable' - push: - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} - services: - # Spin up a postgres:15 container to be used as the dev-database for analysis. - postgres: - image: postgres:15 + dev-url: '${{ secrets.DEV_DATABRICKS_URL }}' + dir: 'file://migrations' + dir-name: 'databricks-demo' env: - POSTGRES_DB: dev - POSTGRES_PASSWORD: pass - ports: - - 5432:5432 - options: >- - --health-cmd pg_isready - --health-interval 10s - --health-start-period 10s - --health-timeout 5s - --health-retries 5 - runs-on: ubuntu-latest - env: - GITHUB_TOKEN: ${{ github.token }} - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - uses: ariga/setup-atlas@v0 - with: - cloud-token: ${{ secrets.ATLAS_CLOUD_TOKEN }} - - uses: ariga/atlas-action/schema/plan/approve@v1 - id: plan-approve - with: - env: ci - dev-url: 'postgres://postgres:pass@localhost:5432/dev?search_path=public&sslmode=disable' - - uses: ariga/atlas-action/schema/push@v1 - with: - env: ci - dev-url: 'postgres://postgres:pass@localhost:5432/dev?search_path=public&sslmode=disable' - - uses: ariga/atlas-action/schema/apply@v1 - with: - env: ci - dev-url: 'postgres://postgres:pass@localhost:5432/dev?search_path=public&sslmode=disable' \ No newline at end of file + GITHUB_TOKEN: '${{ github.token }}' + - uses: ariga/atlas-action/migrate/push@v1 + if: github.ref == 'refs/heads/main' + with: + dir: 'file://migrations' + dev-url: '${{ secrets.DEV_DATABRICKS_URL }}' + dir-name: 'databricks-demo' + - uses: ariga/atlas-action/migrate/apply@v1 + if: github.ref == 'refs/heads/main' + with: + dir: 'file://migrations' + url: '${{ secrets.DB_URL }}' diff --git a/migrations/20250623120536_v1.sql b/migrations/20250623120536_v1.sql deleted file mode 100644 index 705a552..0000000 --- a/migrations/20250623120536_v1.sql +++ /dev/null @@ -1,75 +0,0 @@ --- Create "Products" table -CREATE TABLE `Products` ( - `ProductId` STRING(36) NOT NULL DEFAULT (GENERATE_UUID()), - `Name` STRING(2621440), - `Price` NUMERIC NOT NULL, - `CreatedAt` TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp = true) -) PRIMARY KEY (`ProductId`); --- Create "Inventory" table -CREATE TABLE `Inventory` ( - `ProductId` STRING(36) NOT NULL, - `Location` STRING(100) NOT NULL, - `Quantity` INT64 NOT NULL, - `UpdatedAt` TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp = true), - CONSTRAINT `FK_Inv_Product` FOREIGN KEY (`ProductId`) REFERENCES `Products` (`ProductId`) ON DELETE NO ACTION -) PRIMARY KEY (`ProductId`, `Location`), -INTERLEAVE IN PARENT `Products` ON DELETE CASCADE; --- Create "Customers" table -CREATE TABLE `Customers` ( - `CustomerId` STRING(36) NOT NULL DEFAULT (GENERATE_UUID()), - `Name` STRING(2621440) NOT NULL, - `CreatedAt` TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp = true) -) PRIMARY KEY (`CustomerId`); --- Create "Orders" table -CREATE TABLE `Orders` ( - `CustomerId` STRING(36) NOT NULL, - `OrderId` INT64 NOT NULL, - `ProductId` STRING(36) NOT NULL, - `OrderDate` DATE NOT NULL, - `TotalAmount` NUMERIC NOT NULL, - `UpdatedAt` TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp = true), - CONSTRAINT `FK_Order_Customer` FOREIGN KEY (`CustomerId`) REFERENCES `Customers` (`CustomerId`) ON DELETE NO ACTION, - CONSTRAINT `FK_Order_Product` FOREIGN KEY (`ProductId`) REFERENCES `Products` (`ProductId`) ON DELETE NO ACTION -) PRIMARY KEY (`CustomerId`, `OrderId`), -INTERLEAVE IN PARENT `Customers` ON DELETE CASCADE; --- Create "OrderItems" table -CREATE TABLE `OrderItems` ( - `CustomerId` STRING(36) NOT NULL, - `OrderId` INT64 NOT NULL, - `ItemId` INT64 NOT NULL, - `ProductId` STRING(36) NOT NULL, - `Quantity` INT64 NOT NULL, - `Price` NUMERIC NOT NULL, - CONSTRAINT `FK_OI_Order` FOREIGN KEY (`CustomerId`, `OrderId`) REFERENCES `Orders` (`CustomerId`, `OrderId`) ON DELETE NO ACTION, - CONSTRAINT `FK_OI_Product` FOREIGN KEY (`ProductId`) REFERENCES `Products` (`ProductId`) ON DELETE NO ACTION -) PRIMARY KEY (`CustomerId`, `OrderId`, `ItemId`), -INTERLEAVE IN PARENT `Orders` ON DELETE CASCADE; --- Create "OrdersByDate" table -CREATE TABLE `OrdersByDate` ( - `OrderDate` DATE NOT NULL, - `CustomerId` STRING(36) NOT NULL, - `OrderId` INT64 NOT NULL, - `TotalAmount` NUMERIC NOT NULL, - CONSTRAINT `FK_OBD_Order` FOREIGN KEY (`CustomerId`, `OrderId`) REFERENCES `Orders` (`CustomerId`, `OrderId`) ON DELETE NO ACTION -) PRIMARY KEY (`OrderDate`, `CustomerId`, `OrderId`); --- Create "IDX_OrdersByDate_TotalAmount" index -CREATE INDEX `IDX_OrdersByDate_TotalAmount` ON `OrdersByDate` (`TotalAmount`, `OrderDate` DESC); --- Create "Reviews" table -CREATE TABLE `Reviews` ( - `ProductId` STRING(36) NOT NULL, - `ReviewId` INT64 NOT NULL, - `CustomerId` STRING(36) NOT NULL, - `Rating` INT64 NOT NULL, - `Comment` STRING(2621440), - `CreatedTS` TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp = true), - CONSTRAINT `FK_Rev_Customer` FOREIGN KEY (`CustomerId`) REFERENCES `Customers` (`CustomerId`) ON DELETE NO ACTION, - CONSTRAINT `FK_Rev_Product` FOREIGN KEY (`ProductId`) REFERENCES `Products` (`ProductId`) ON DELETE NO ACTION -) PRIMARY KEY (`ProductId`, `ReviewId`), -INTERLEAVE IN PARENT `Products` ON DELETE CASCADE; --- Create "Sessions" table -CREATE TABLE `Sessions` ( - `SessionId` STRING(36) NOT NULL DEFAULT (GENERATE_UUID()), - `CustomerId` STRING(36) NOT NULL, - `LastAccess` TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp = true), - CONSTRAINT `FK_Sess_Customer` FOREIGN KEY (`CustomerId`) REFERENCES `Customers` (`CustomerId`) ON DELETE NO ACTION -) PRIMARY KEY (`SessionId`); diff --git a/migrations/20250626123506_v2.sql b/migrations/20250626123506_v2.sql deleted file mode 100644 index 69f8a40..0000000 --- a/migrations/20250626123506_v2.sql +++ /dev/null @@ -1,4 +0,0 @@ --- Modify column "Quantity" in table "Inventory" -ALTER TABLE `Inventory` ALTER COLUMN `Quantity` INT64 NOT NULL DEFAULT (0); --- Modify column "Price" in table "OrderItems" -ALTER TABLE `OrderItems` ALTER COLUMN `Price` NUMERIC; diff --git a/migrations/20250626123922_v3.sql b/migrations/20250626123922_v3.sql deleted file mode 100644 index 084ef38..0000000 --- a/migrations/20250626123922_v3.sql +++ /dev/null @@ -1,2 +0,0 @@ --- Add column "arrayQuantity" to table "Inventory" -ALTER TABLE `Inventory` ADD COLUMN `arrayQuantity` ARRAY NOT NULL DEFAULT ([]); diff --git a/migrations/20250626124204_v4.sql b/migrations/20250626124204_v4.sql deleted file mode 100644 index 1cbf323..0000000 --- a/migrations/20250626124204_v4.sql +++ /dev/null @@ -1,2 +0,0 @@ --- Add check "ab" to table "Orders" -ALTER TABLE `Orders` ADD CONSTRAINT `ab` CHECK (TotalAmount > 0 AND OrderDate IS NOT NULL); diff --git a/migrations/20250626124240_v5_drop_fk.sql b/migrations/20250626124240_v5_drop_fk.sql deleted file mode 100644 index 0d9b000..0000000 --- a/migrations/20250626124240_v5_drop_fk.sql +++ /dev/null @@ -1,2 +0,0 @@ --- Drop foreign key "FK_OI_Product" from table "OrderItems" -ALTER TABLE `OrderItems` DROP CONSTRAINT `FK_OI_Product`; diff --git a/migrations/20250626125310_v6_drop_col.sql b/migrations/20250626125310_v6_drop_col.sql deleted file mode 100644 index 4109b8b..0000000 --- a/migrations/20250626125310_v6_drop_col.sql +++ /dev/null @@ -1,2 +0,0 @@ --- Drop column "UpdatedAt" from table "Orders" -ALTER TABLE `Orders` DROP COLUMN `UpdatedAt`; diff --git a/migrations/20250626125426_v7_drop_table.sql b/migrations/20250626125426_v7_drop_table.sql deleted file mode 100644 index 099b3eb..0000000 --- a/migrations/20250626125426_v7_drop_table.sql +++ /dev/null @@ -1,4 +0,0 @@ --- Drop index named "IDX_OrdersByDate_TotalAmount" -DROP INDEX `IDX_OrdersByDate_TotalAmount`; --- Drop table named "OrdersByDate" -DROP TABLE `OrdersByDate`; diff --git a/migrations/20250626132249_checkpoint.sql b/migrations/20250626132249_checkpoint.sql deleted file mode 100644 index 2cfb465..0000000 --- a/migrations/20250626132249_checkpoint.sql +++ /dev/null @@ -1,67 +0,0 @@ --- atlas:checkpoint - --- Create "Products" table -CREATE TABLE `Products` ( - `ProductId` STRING(36) NOT NULL DEFAULT (GENERATE_UUID()), - `Name` STRING(2621440), - `Price` NUMERIC NOT NULL, - `CreatedAt` TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp = true) -) PRIMARY KEY (`ProductId`); --- Create "Inventory" table -CREATE TABLE `Inventory` ( - `ProductId` STRING(36) NOT NULL, - `Location` STRING(100) NOT NULL, - `Quantity` INT64 NOT NULL DEFAULT (0), - `UpdatedAt` TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp = true), - `arrayQuantity` ARRAY NOT NULL DEFAULT ([]), - CONSTRAINT `FK_Inv_Product` FOREIGN KEY (`ProductId`) REFERENCES `Products` (`ProductId`) ON DELETE NO ACTION -) PRIMARY KEY (`ProductId`, `Location`), -INTERLEAVE IN PARENT `Products` ON DELETE CASCADE; --- Create "Customers" table -CREATE TABLE `Customers` ( - `CustomerId` STRING(36) NOT NULL DEFAULT (GENERATE_UUID()), - `Name` STRING(2621440) NOT NULL, - `CreatedAt` TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp = true) -) PRIMARY KEY (`CustomerId`); --- Create "Orders" table -CREATE TABLE `Orders` ( - `CustomerId` STRING(36) NOT NULL, - `OrderId` INT64 NOT NULL, - `ProductId` STRING(36) NOT NULL, - `OrderDate` DATE NOT NULL, - `TotalAmount` NUMERIC NOT NULL, - CONSTRAINT `FK_Order_Customer` FOREIGN KEY (`CustomerId`) REFERENCES `Customers` (`CustomerId`) ON DELETE NO ACTION, - CONSTRAINT `FK_Order_Product` FOREIGN KEY (`ProductId`) REFERENCES `Products` (`ProductId`) ON DELETE NO ACTION, - CONSTRAINT `ab` CHECK (TotalAmount > 0 AND OrderDate IS NOT NULL) -) PRIMARY KEY (`CustomerId`, `OrderId`), -INTERLEAVE IN PARENT `Customers` ON DELETE CASCADE; --- Create "OrderItems" table -CREATE TABLE `OrderItems` ( - `CustomerId` STRING(36) NOT NULL, - `OrderId` INT64 NOT NULL, - `ItemId` INT64 NOT NULL, - `ProductId` STRING(36) NOT NULL, - `Quantity` INT64 NOT NULL, - `Price` NUMERIC, - CONSTRAINT `FK_OI_Order` FOREIGN KEY (`CustomerId`, `OrderId`) REFERENCES `Orders` (`CustomerId`, `OrderId`) ON DELETE NO ACTION -) PRIMARY KEY (`CustomerId`, `OrderId`, `ItemId`), -INTERLEAVE IN PARENT `Orders` ON DELETE CASCADE; --- Create "Reviews" table -CREATE TABLE `Reviews` ( - `ProductId` STRING(36) NOT NULL, - `ReviewId` INT64 NOT NULL, - `CustomerId` STRING(36) NOT NULL, - `Rating` INT64 NOT NULL, - `Comment` STRING(2621440), - `CreatedTS` TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp = true), - CONSTRAINT `FK_Rev_Customer` FOREIGN KEY (`CustomerId`) REFERENCES `Customers` (`CustomerId`) ON DELETE NO ACTION, - CONSTRAINT `FK_Rev_Product` FOREIGN KEY (`ProductId`) REFERENCES `Products` (`ProductId`) ON DELETE NO ACTION -) PRIMARY KEY (`ProductId`, `ReviewId`), -INTERLEAVE IN PARENT `Products` ON DELETE CASCADE; --- Create "Sessions" table -CREATE TABLE `Sessions` ( - `SessionId` STRING(36) NOT NULL DEFAULT (GENERATE_UUID()), - `CustomerId` STRING(36) NOT NULL, - `LastAccess` TIMESTAMP NOT NULL OPTIONS (allow_commit_timestamp = true), - CONSTRAINT `FK_Sess_Customer` FOREIGN KEY (`CustomerId`) REFERENCES `Customers` (`CustomerId`) ON DELETE NO ACTION -) PRIMARY KEY (`SessionId`); diff --git a/migrations/20250629115627_v8_drop_column.sql b/migrations/20250629115627_v8_drop_column.sql deleted file mode 100644 index 9cf74e6..0000000 --- a/migrations/20250629115627_v8_drop_column.sql +++ /dev/null @@ -1,2 +0,0 @@ --- atlas:nolint DS103 -ALTER TABLE `Reviews` DROP COLUMN `Rating`; diff --git a/migrations/20250630075631_v9_drop_more_column.sql b/migrations/20250630075631_v9_drop_more_column.sql deleted file mode 100644 index d50c84e..0000000 --- a/migrations/20250630075631_v9_drop_more_column.sql +++ /dev/null @@ -1,9 +0,0 @@ --- atlas:txtar - --- checks/destructive.sql -- --- atlas:assert DS103 -SELECT IF (EXISTS (SELECT 1 FROM `Reviews` WHERE `Comment` IS NOT NULL), 0, 1) AS `is_empty`; - --- migration.sql -- --- Drop column "Comment" from table "Reviews" -ALTER TABLE `Reviews` DROP COLUMN `Comment`; \ No newline at end of file diff --git a/migrations/20251019081741_init.sql b/migrations/20251019081741_init.sql new file mode 100644 index 0000000..2b48a4a --- /dev/null +++ b/migrations/20251019081741_init.sql @@ -0,0 +1,11 @@ +CREATE TABLE IF NOT EXISTS users ( + user_id BIGINT NOT NULL, + name STRING, + email STRING, + created_at TIMESTAMP +) +USING delta +TBLPROPERTIES ( + 'delta.autoOptimize.optimizeWrite' = 'true', + 'delta.autoOptimize.autoCompact' = 'true' +); diff --git a/migrations/atlas.sum b/migrations/atlas.sum index e117eda..3ee7fcd 100644 --- a/migrations/atlas.sum +++ b/migrations/atlas.sum @@ -1,11 +1,2 @@ -h1:2wD6xiUAJ0Sa8pOAfPzS2XG/JwfqRqM574sehzBc2UQ= -20250623120536_v1.sql h1:H003UXn06tr6/7xk2Ao75gjsyCIPZei7XgsVC4z4Hzk= -20250626123506_v2.sql h1:KpcwYLYS75uXnwWzlAfMXxNZeR2hYANasYK+pCLqLrc= -20250626123922_v3.sql h1:/5ut3XUVGvymCmMNQBJh++ekWbCW8H7NgyGJLyaidPM= -20250626124204_v4.sql h1:lj/F8l2DM1EXD2ZyVwyaVLhOToOhQ3cTqN4VKPWQj/w= -20250626124240_v5_drop_fk.sql h1:TBL+e1GP1+q+ns65JUhG6f61dVfWjcRkbxNcDoHEupA= -20250626125310_v6_drop_col.sql h1:hW8UBFmzBVXbqlHPNkO5LEBp1vTaPJMgcJ7P6s6Bo6g= -20250626125426_v7_drop_table.sql h1:tv9BQjv4xaAECoNBqAL3kpNK3klOxiQ1vOxgP+FMjDI= -20250626132249_checkpoint.sql h1:0uxqK5OkdPJRy9EbxJShtx8oSXQ9Txc3R7ly/jLH0PU= -20250629115627_v8_drop_column.sql h1:hE/PuQ0kuwSer+a6l0X+n3iNaPGgBC2ve3DPvetWkrM= -20250630075631_v9_drop_more_column.sql h1:FpqoD8nw0eZJMURxWeO4rSGwvsm8TldALRFvGml0M48= +h1:zDkasFnjaXDWodrK4DMjfsD+FOLfuPVLB3R2AiE70Ek= +20251019081741_init.sql h1:5WYPKesNylGppoSKPLRD59pDWBi0j5jTf4nD3LS1oX8=