basic

package
v0.0.0-...-d364ca2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package basic is a compiling Phase 1 example application model.

Index

Constants

This section is empty.

Variables

View Source
var Migrations = []migrate.Migration{
	{
		Name: "001_create_accounts",
		Up: []string{
			`CREATE TABLE accounts (
    id UUID PRIMARY KEY,
    name VARCHAR(255) NOT NULL DEFAULT '',
    description TEXT NOT NULL DEFAULT '',
    metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    deleted_at TIMESTAMPTZ NULL,
    created_by UUID NULL,
    updated_by UUID NULL,
    deleted_by UUID NULL,
    slug VARCHAR(255) NOT NULL
)`,
			`CREATE UNIQUE INDEX accounts_slug_unique ON accounts (slug) WHERE deleted_at IS NULL`,
		},
		Down: []string{`DROP TABLE accounts`},
	},
	{
		Name: "002_create_users",
		Up: []string{
			`CREATE TABLE users (
    id UUID PRIMARY KEY,
    name VARCHAR(255) NOT NULL DEFAULT '',
    description TEXT NOT NULL DEFAULT '',
    metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    deleted_at TIMESTAMPTZ NULL,
    created_by UUID NULL,
    updated_by UUID NULL,
    deleted_by UUID NULL,
    email VARCHAR(255) NOT NULL,
    active BOOLEAN NOT NULL DEFAULT TRUE,
    account_id UUID NULL REFERENCES accounts(id)
)`,
			`CREATE UNIQUE INDEX users_email_unique ON users (email) WHERE deleted_at IS NULL`,
		},
		Down: []string{`DROP TABLE users`},
	},
	{
		Name: "003_create_projects",
		Up: []string{
			`CREATE TABLE projects (
    id UUID PRIMARY KEY,
    name VARCHAR(255) NOT NULL DEFAULT '',
    description TEXT NOT NULL DEFAULT '',
    metadata JSONB NOT NULL DEFAULT '{}'::jsonb,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    deleted_at TIMESTAMPTZ NULL,
    created_by UUID NULL,
    updated_by UUID NULL,
    deleted_by UUID NULL,
    account_id UUID NOT NULL REFERENCES accounts(id),
    owner_id UUID NULL REFERENCES users(id),
    status VARCHAR(64) NOT NULL
)`,
			`CREATE INDEX projects_account_id_idx ON projects (account_id)`,
			`CREATE INDEX projects_owner_id_idx ON projects (owner_id)`,
			`CREATE INDEX projects_status_idx ON projects (status)`,
		},
		Down: []string{`DROP TABLE projects`},
	},
}

Functions

func NewAccountFactory

func NewAccountFactory(accounts *repository.Repository[Account]) (*factory.Factory[Account], error)

func NewProjectFactory

func NewProjectFactory(projects *repository.Repository[Project], accountID uuid.UUID, ownerID *uuid.UUID) (*factory.Factory[Project], error)

func NewUserFactory

func NewUserFactory(users *repository.Repository[User]) (*factory.Factory[User], error)

func NewUserResourceWithJobs

func NewUserResourceWithJobs(dbRepository *repository.Repository[User], jobClient *jobs.Client) (*api.Resource[User, CreateUserInput, UpdateUserInput, UserResponse], error)

func RegisterJobs

func RegisterJobs(jobClient *jobs.Client, users *repository.Repository[User], mailer *mail.Client) error

func Seed

func Seed(ctx context.Context, users *repository.Repository[User]) error

Seed inserts one predictable development user and is safe to run repeatedly.

func SeedApplication

func SeedApplication(ctx context.Context, db *database.DB) error

SeedApplication creates an Account/User/Project graph and is idempotent.

Types

type Account

type Account struct {
	model.Base
	Slug string `bun:"slug,notnull" json:"slug" validate:"required,max=255"`
}

func (*Account) BeforeCreate

func (account *Account) BeforeCreate(_ context.Context, _ *lifecycle.Context) error

type AccountResponse

type AccountResponse struct {
	ID        uuid.UUID `json:"id"`
	Name      string    `json:"name"`
	Slug      string    `json:"slug"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type CreateAccountInput

type CreateAccountInput struct {
	Name string `json:"name" minLength:"1" maxLength:"255"`
	Slug string `json:"slug" minLength:"1" maxLength:"255"`
}

type CreateProjectInput

type CreateProjectInput struct {
	Name        string         `json:"name" minLength:"1" maxLength:"255"`
	Description string         `json:"description,omitempty"`
	Metadata    model.Metadata `json:"metadata,omitempty"`
	AccountID   uuid.UUID      `json:"account_id"`
	OwnerID     *uuid.UUID     `json:"owner_id,omitempty"`
	Status      string         `json:"status" minLength:"1" maxLength:"64"`
}

type CreateUserInput

type CreateUserInput struct {
	Name      string     `json:"name" minLength:"1" maxLength:"255"`
	Email     string     `json:"email" format:"email"`
	Active    bool       `json:"active"`
	AccountID *uuid.UUID `json:"account_id,omitempty"`
}

type Project

type Project struct {
	model.Base
	AccountID uuid.UUID  `bun:"account_id,notnull" json:"account_id" validate:"required"`
	OwnerID   *uuid.UUID `bun:"owner_id,nullzero" json:"owner_id,omitempty"`
	Status    string     `bun:"status,notnull" json:"status" validate:"required,max=64"`
}

type ProjectResponse

type ProjectResponse struct {
	ID          uuid.UUID      `json:"id"`
	Name        string         `json:"name"`
	Description string         `json:"description"`
	Metadata    model.Metadata `json:"metadata"`
	AccountID   uuid.UUID      `json:"account_id"`
	OwnerID     *uuid.UUID     `json:"owner_id,omitempty"`
	Status      string         `json:"status"`
	CreatedAt   time.Time      `json:"created_at"`
	UpdatedAt   time.Time      `json:"updated_at"`
}

type SendWelcomeEmail

type SendWelcomeEmail struct {
	UserID uuid.UUID `json:"user_id" river:"unique"`
}

func (SendWelcomeEmail) Kind

func (SendWelcomeEmail) Kind() string

type UpdateAccountInput

type UpdateAccountInput struct {
	Name *string `json:"name,omitempty" minLength:"1" maxLength:"255"`
	Slug *string `json:"slug,omitempty" minLength:"1" maxLength:"255"`
}

type UpdateProjectInput

type UpdateProjectInput struct {
	Name        *string         `json:"name,omitempty" minLength:"1" maxLength:"255"`
	Description *string         `json:"description,omitempty"`
	Metadata    *model.Metadata `json:"metadata,omitempty"`
	OwnerID     **uuid.UUID     `json:"owner_id,omitempty"`
	Status      *string         `json:"status,omitempty" minLength:"1" maxLength:"64"`
}

type UpdateUserInput

type UpdateUserInput struct {
	Name      *string     `json:"name,omitempty" minLength:"1" maxLength:"255"`
	Email     *string     `json:"email,omitempty" format:"email"`
	Active    *bool       `json:"active,omitempty"`
	AccountID **uuid.UUID `json:"account_id,omitempty"`
}

type User

type User struct {
	model.Base
	Email     string     `bun:"email,notnull" json:"email" validate:"required,email"`
	Active    bool       `bun:"active,notnull,default:true" json:"active"`
	AccountID *uuid.UUID `bun:"account_id,nullzero" json:"account_id,omitempty"`

	EmailChanged bool `bun:"-" json:"-"`
}

func (*User) AfterUpdate

func (user *User) AfterUpdate(_ context.Context, lifecycleContext *lifecycle.Context) error

func (*User) BeforeCreate

func (user *User) BeforeCreate(_ context.Context, _ *lifecycle.Context) error

type UserResponse

type UserResponse struct {
	ID        uuid.UUID  `json:"id"`
	Name      string     `json:"name"`
	Email     string     `json:"email"`
	Active    bool       `json:"active"`
	AccountID *uuid.UUID `json:"account_id,omitempty"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
}

Directories

Path Synopsis
cmd
demo command
server command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL