10
pkg/probo/coredata/migrations.go
Normal file
10
pkg/probo/coredata/migrations.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package coredata
|
||||
|
||||
import (
|
||||
"embed"
|
||||
)
|
||||
|
||||
var (
|
||||
//go:embed migrations/*.sql
|
||||
Migrations embed.FS
|
||||
)
|
||||
37
pkg/probo/coredata/migrations/20250124T113100Z.sql
Normal file
37
pkg/probo/coredata/migrations/20250124T113100Z.sql
Normal file
@@ -0,0 +1,37 @@
|
||||
CREATE TABLE organizations (
|
||||
id UUID PRIMARY KEY,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE frameworks (
|
||||
id UUID PRIMARY KEY,
|
||||
organization_id UUID REFERENCES organizations(id) NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
content_ref TEXT NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE controls (
|
||||
id UUID PRIMARY KEY,
|
||||
framework_id UUID REFERENCES frameworks(id) NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
content_ref TEXT NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE tasks (
|
||||
id UUID PRIMARY KEY,
|
||||
control_id UUID REFERENCES controls(id) NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
description TEXT NOT NULL,
|
||||
content_ref TEXT NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||
updated_at TIMESTAMP WITH TIME ZONE NOT NULL
|
||||
);
|
||||
@@ -16,10 +16,12 @@ package probo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/getprobo/probo/pkg/probo/coredata"
|
||||
"github.com/getprobo/probo/pkg/probo/coredata/gid"
|
||||
"github.com/getprobo/probo/pkg/probo/coredata/page"
|
||||
"go.gearno.de/kit/migrator"
|
||||
"go.gearno.de/kit/pg"
|
||||
)
|
||||
|
||||
@@ -30,11 +32,16 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func NewService(ctx context.Context, pgClient *pg.Client) *Service {
|
||||
func NewService(ctx context.Context, pgClient *pg.Client) (*Service, error) {
|
||||
err := migrator.NewMigrator(pgClient, coredata.Migrations).Run(ctx, "migrations")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot migrate database schema: %w", err)
|
||||
}
|
||||
|
||||
return &Service{
|
||||
pg: pgClient,
|
||||
scope: coredata.NewScope(), // must be created from auth
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Service) GetOrganization(
|
||||
|
||||
@@ -94,7 +94,10 @@ func (impl *Implm) Run(
|
||||
return fmt.Errorf("cannot create pg client: %w", err)
|
||||
}
|
||||
|
||||
probo := probo.NewService(ctx, pgClient)
|
||||
probo, err := probo.NewService(ctx, pgClient)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create probo service: %w", err)
|
||||
}
|
||||
|
||||
apiServer, err := api.NewServer(
|
||||
api.Config{
|
||||
|
||||
Reference in New Issue
Block a user