Skip to content

Commit

Permalink
Merge pull request #7 from lbennett-stacki/cloud
Browse files Browse the repository at this point in the history
Cloud
  • Loading branch information
lbennett-stacki authored Jul 8, 2024
2 parents 98a20d9 + 409c093 commit 669a3e3
Show file tree
Hide file tree
Showing 220 changed files with 5,715 additions and 739 deletions.
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
target
node_modules
dist
tarpaulin-report.html
load-test-results.html
2 changes: 2 additions & 0 deletions cloud/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
local.db
local.db-*
34 changes: 34 additions & 0 deletions cloud/Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Config

NAME := "envy"
ENV := "development"
DATABASE_DIR := "db"
DATABASE_SCHEMA_DIR := "schema"

# Database

## Database - Private
db-name:
@echo {{NAME}}-{{ENV}}
db-url:
@turso db show $(just db-name) --url
db-create:
turso db create $(just db-name)
db-token:
@turso db tokens create $(just db-name)

## Database - Public

db-login:
turso auth login
atlas login
db-migrate:
cd {{DATABASE_DIR}} && \
atlas schema apply -u "$(just db-url)?authToken=$(just db-token)" \
--to file://{{DATABASE_SCHEMA_DIR}} --exclude '_litestream_seq,_litestream_lock'
db-lint:
cd {{DATABASE_DIR}} && \
atlas migrate lint --dev-url "sqlite://dev?mode=memory" -w
db-diff:
cd {{DATABASE_DIR}} && \
atlas migrate diff --to file://{{DATABASE_SCHEMA_DIR}} --dev-url "sqlite://dev?mode=memory"
21 changes: 21 additions & 0 deletions cloud/api/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

import (
"log"

"github.com/gofiber/fiber/v2"
)

func main() {
app := fiber.New()

app.Get("/", func(c *fiber.Ctx) error {
return c.SendString("Hello, World!")
})

app.Get("/api/posts", func(c *fiber.Ctx) error {
return c.SendString("Hello, posts!")
})

log.Fatal(app.Listen(":3000"))
}
18 changes: 18 additions & 0 deletions cloud/api/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module nv-api

go 1.22.3

require (
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/gofiber/fiber/v2 v2.52.5 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.51.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/sys v0.15.0 // indirect
)
27 changes: 27 additions & 0 deletions cloud/api/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/gofiber/fiber/v2 v2.52.5 h1:tWoP1MJQjGEe4GB5TUGOi7P2E0ZMMRx5ZTG4rT+yGMo=
github.com/gofiber/fiber/v2 v2.52.5/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
13 changes: 13 additions & 0 deletions cloud/db/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Envy Database

## Release

Run migrations:

- `atlas migrate diff`
- `atlas migrate lint`
- `atlas schema apply`

```
```
23 changes: 23 additions & 0 deletions cloud/db/atlas.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
variable "turso_token" {
type = string
default = getenv("TURSO_TOKEN")
}

variable "cloud_token" {
type = string
default = getenv("ATLAS_TOKEN")
}

atlas {
cloud {
token = var.cloud_token
}
}

env "development" {
url = "libsql+wss://envy-development-lbennett-stacki.turso.io?authToken=${var.turso_token}"
exclude = ["_litestream*"]
migration {
dir = "atlas://envy"
}
}
18 changes: 18 additions & 0 deletions cloud/db/migrations/20240708231157.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- Create "environment_variables" table
CREATE TABLE `environment_variables` (`id` uuid NOT NULL, `environment_id` uuid NOT NULL, `variable_id` uuid NOT NULL, `created_at` date NOT NULL, PRIMARY KEY (`id`), CONSTRAINT `environment_fk` FOREIGN KEY (`environment_id`) REFERENCES `environments` (`id`), CONSTRAINT `variable_fk` FOREIGN KEY (`variable_id`) REFERENCES `variables` (`id`));
-- Create "environments" table
CREATE TABLE `environments` (`id` uuid NOT NULL, `name` varchar NOT NULL, `project_id` uuid NOT NULL, `created_at` date NOT NULL, `updated_at` date NULL, PRIMARY KEY (`id`), CONSTRAINT `project_fk` FOREIGN KEY (`project_id`) REFERENCES `projects` (`id`));
-- Create "organisation_members" table
CREATE TABLE `organisation_members` (`id` uuid NOT NULL, `is_owner` bool NOT NULL, `user_id` uuid NOT NULL, `organisation_id` uuid NOT NULL, `created_at` date NOT NULL, PRIMARY KEY (`id`), CONSTRAINT `user_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`), CONSTRAINT `organisation_fk` FOREIGN KEY (`organisation_id`) REFERENCES `organisations` (`id`));
-- Create "organisations" table
CREATE TABLE `organisations` (`id` uuid NOT NULL, `name` varchar NOT NULL, `created_at` date NOT NULL, `updated_at` date NULL, PRIMARY KEY (`id`));
-- Create "project_members" table
CREATE TABLE `project_members` (`id` uuid NOT NULL, `user_id` uuid NOT NULL, `project_id` uuid NOT NULL, `created_at` date NOT NULL, PRIMARY KEY (`id`), CONSTRAINT `user_fk` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`), CONSTRAINT `project_fk` FOREIGN KEY (`project_id`) REFERENCES `projects` (`id`));
-- Create "projects" table
CREATE TABLE `projects` (`id` uuid NOT NULL, `name` varchar NOT NULL, `organisation_id` uuid NULL, `created_at` date NOT NULL, `updated_at` date NULL, PRIMARY KEY (`id`), CONSTRAINT `organisation_fk` FOREIGN KEY (`organisation_id`) REFERENCES `organisations` (`id`));
-- Create "users" table
CREATE TABLE `users` (`id` uuid NOT NULL, `first_name` varchar NOT NULL, `last_name` varchar NOT NULL, `email` varchar NOT NULL, `password` varchar NOT NULL, `language` varchar NOT NULL, `currency` varchar NOT NULL, `created_at` date NOT NULL, `updated_at` date NULL, PRIMARY KEY (`id`));
-- Create "variable_values" table
CREATE TABLE `variable_values` (`id` uuid NOT NULL, `value` varchar NOT NULL, `variable_id` uuid NOT NULL, `created_at` date NOT NULL, PRIMARY KEY (`id`), CONSTRAINT `variable_fk` FOREIGN KEY (`variable_id`) REFERENCES `variables` (`id`));
-- Create "variables" table
CREATE TABLE `variables` (`id` uuid NOT NULL, `key` varchar NOT NULL, `description` varchar NOT NULL, `is_private` bool NOT NULL, `project_id` uuid NOT NULL, `created_at` date NOT NULL, `updated_at` date NULL, PRIMARY KEY (`id`), CONSTRAINT `project_fk` FOREIGN KEY (`project_id`) REFERENCES `projects` (`id`));
4 changes: 4 additions & 0 deletions cloud/db/migrations/20240708231540.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Add column "archived_at" to table: "organisations"
ALTER TABLE `organisations` ADD COLUMN `archived_at` date NULL;
-- Add column "archived_at" to table: "projects"
ALTER TABLE `projects` ADD COLUMN `archived_at` date NULL;
3 changes: 3 additions & 0 deletions cloud/db/migrations/atlas.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h1:PP+OhMcpMj3j4wAMuRwRMhTxYtw27+xGvS923M0fbVA=
20240708231157.sql h1:lQoYoQLKeyRq8BPhbQiV9nUU3chmrMyr/dYtELrsa+c=
20240708231540.sql h1:KiErym5hYOhJBPrwxnCSdDpDIhhLZfnCo5oZmLq+QvY=
32 changes: 32 additions & 0 deletions cloud/db/schema/environment_variables.atlas.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
table "environment_variables" {
schema = schema.main

column "id" {
type = uuid
}
primary_key {
columns = [
column.id
]
}

column "environment_id" {
type = uuid
}
foreign_key "environment_fk" {
columns = [column.environment_id]
ref_columns = [table.environments.column.id]
}

column "variable_id" {
type = uuid
}
foreign_key "variable_fk" {
columns = [column.variable_id]
ref_columns = [table.variables.column.id]
}

column "created_at" {
type = date
}
}
33 changes: 33 additions & 0 deletions cloud/db/schema/environments.atlas.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
table "environments" {
schema = schema.main

column "id" {
type = uuid
}
primary_key {
columns = [
column.id
]
}

column "name" {
type = varchar(255)
}

column "project_id" {
type = uuid
}
foreign_key "project_fk" {
columns = [column.project_id]
ref_columns = [table.projects.column.id]
}

column "created_at" {
type = date
}

column "updated_at" {
type = date
null = true
}
}
36 changes: 36 additions & 0 deletions cloud/db/schema/organisation_members.atlas.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
table "organisation_members" {
schema = schema.main

column "id" {
type = uuid
}
primary_key {
columns = [
column.id
]
}

column "is_owner" {
type = bool
}

column "user_id" {
type = uuid
}
foreign_key "user_fk" {
columns = [column.user_id]
ref_columns = [table.users.column.id]
}

column "organisation_id" {
type = uuid
}
foreign_key "organisation_fk" {
columns = [column.organisation_id]
ref_columns = [table.organisations.column.id]
}

column "created_at" {
type = date
}
}
30 changes: 30 additions & 0 deletions cloud/db/schema/organisations.atlas.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
table "organisations" {
schema = schema.main

column "id" {
type = uuid
}
primary_key {
columns = [
column.id
]
}

column "name" {
type = varchar(255)
}

column "created_at" {
type = date
}

column "updated_at" {
type = date
null = true
}

column "archived_at" {
type = date
null = true
}
}
32 changes: 32 additions & 0 deletions cloud/db/schema/project_members.atlas.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
table "project_members" {
schema = schema.main

column "id" {
type = uuid
}
primary_key {
columns = [
column.id
]
}

column "user_id" {
type = uuid
}
foreign_key "user_fk" {
columns = [column.user_id]
ref_columns = [table.users.column.id]
}

column "project_id" {
type = uuid
}
foreign_key "project_fk" {
columns = [column.project_id]
ref_columns = [table.projects.column.id]
}

column "created_at" {
type = date
}
}
39 changes: 39 additions & 0 deletions cloud/db/schema/projects.atlas.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
table "projects" {
schema = schema.main

column "id" {
type = uuid
}
primary_key {
columns = [
column.id
]
}

column "name" {
type = varchar(255)
}

column "organisation_id" {
type = uuid
null = true
}
foreign_key "organisation_fk" {
columns = [column.organisation_id]
ref_columns = [table.organisations.column.id]
}

column "created_at" {
type = date
}

column "updated_at" {
type = date
null = true
}

column "archived_at" {
type = date
null = true
}
}
1 change: 1 addition & 0 deletions cloud/db/schema/schema.atlas.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
schema "main" {}
Loading

0 comments on commit 669a3e3

Please sign in to comment.