Skip to content

Commit

Permalink
projects/estore: init
Browse files Browse the repository at this point in the history
  • Loading branch information
rotemtam committed Mar 7, 2024
1 parent 68c9622 commit 11d0fc1
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/estore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Setup Atlas

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Atlas
uses: ariga/setup-atlas@v0
with:
token: ${{ secrets.ATLAS_PUBLIC_TENANT_TOKEN }}
12 changes: 12 additions & 0 deletions projects/estore/atlas.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
env "local" {
src = "file://inventory/schema.hcl"
dev = "docker://mysql/8/default"
migration {
dir = "file://inventory/migrations"
}
format {
migrate {
diff = "{{ sql . \" \" }}"
}
}
}
28 changes: 28 additions & 0 deletions projects/estore/inventory/migrations/20240307092728.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- Create "categories" table
CREATE TABLE `categories` (
`category_id` int NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`description` text NULL,
PRIMARY KEY (`category_id`)
) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
-- Create "suppliers" table
CREATE TABLE `suppliers` (
`supplier_id` int NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`contact_info` text NULL,
PRIMARY KEY (`supplier_id`)
) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
-- Create "products" table
CREATE TABLE `products` (
`product_id` int NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`category_id` int NULL,
`supplier_id` int NULL,
`price` decimal(10,2) NOT NULL,
`description` text NULL,
PRIMARY KEY (`product_id`),
INDEX `category_id` (`category_id`),
INDEX `supplier_id` (`supplier_id`),
CONSTRAINT `products_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `categories` (`category_id`) ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT `products_ibfk_2` FOREIGN KEY (`supplier_id`) REFERENCES `suppliers` (`supplier_id`) ON UPDATE NO ACTION ON DELETE NO ACTION
) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
2 changes: 2 additions & 0 deletions projects/estore/inventory/migrations/atlas.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
h1:fo2R2MvvR2SDqpcg3lMGjPvOwppIJ3AIR7rtGh5zPpU=
20240307092728.sql h1:BEXRAbglZQlUqXHRy4fvsEVsu7FlSfKcJ/JAkH2XgMY=
92 changes: 92 additions & 0 deletions projects/estore/inventory/schema.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
table "categories" {
schema = schema.default
column "category_id" {
null = false
type = int
auto_increment = true
}
column "name" {
null = false
type = varchar(255)
}
column "description" {
null = true
type = text
}
primary_key {
columns = [column.category_id]
}
}
table "products" {
schema = schema.default
column "product_id" {
null = false
type = int
auto_increment = true
}
column "name" {
null = false
type = varchar(255)
}
column "category_id" {
null = true
type = int
}
column "supplier_id" {
null = true
type = int
}
column "price" {
null = false
type = decimal(10,2)
unsigned = false
}
column "description" {
null = true
type = text
}
primary_key {
columns = [column.product_id]
}
foreign_key "products_ibfk_1" {
columns = [column.category_id]
ref_columns = [table.categories.column.category_id]
on_update = NO_ACTION
on_delete = NO_ACTION
}
foreign_key "products_ibfk_2" {
columns = [column.supplier_id]
ref_columns = [table.suppliers.column.supplier_id]
on_update = NO_ACTION
on_delete = NO_ACTION
}
index "category_id" {
columns = [column.category_id]
}
index "supplier_id" {
columns = [column.supplier_id]
}
}
table "suppliers" {
schema = schema.default
column "supplier_id" {
null = false
type = int
auto_increment = true
}
column "name" {
null = false
type = varchar(255)
}
column "contact_info" {
null = true
type = text
}
primary_key {
columns = [column.supplier_id]
}
}
schema "default" {
charset = "utf8mb4"
collate = "utf8mb4_0900_ai_ci"
}

0 comments on commit 11d0fc1

Please sign in to comment.