schema

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package schema compares a complete application schema with its database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Change

type Change struct {
	Action string `json:"action"`
	Table  string `json:"table"`
	Name   string `json:"name,omitempty"`
	Before string `json:"before,omitempty"`
	After  string `json:"after,omitempty"`
	Risk   bool   `json:"risk"`
}

Change describes one planned operation. Risk marks operations that can affect data.

type Definition

type Definition struct {
	Tables map[string]Table
	Keep   []string
}

Definition is the complete database target. Tables absent from it are dropped. Keep contains runtime-owned table patterns, not a boundary for business tables.

func Resolve

func Resolve() *Definition

Resolve returns the current application target, including business customizations.

func (*Definition) Apply

func (d *Definition) Apply(ctx context.Context, db *gorm.DB, plan *Plan) error

Apply executes the reviewed plan. On failure it returns the precise operation. MySQL DDL may already have committed earlier operations; recheck before retrying.

func (*Definition) Check

func (d *Definition) Check(ctx context.Context, db *gorm.DB, selection ...string) (*Plan, error)

Check compares all tables; an optional selection limits this invocation only.

func (*Definition) Create

func (d *Definition) Create(db *gorm.DB) error

Create creates the complete target, without seeding data or recording migrations.

func (*Definition) Drop

func (d *Definition) Drop(db *gorm.DB) error

Drop drops definition tables in reverse dependency order.

type Plan

type Plan struct {
	Changes []Change `json:"changes"`
}

Plan is read-only; Apply executes these operations against the same definition.

type Table

type Table struct {
	Model   any
	Comment string
}

Table uses ordinary GORM fields, indexes and constraints as the target definition.

Jump to

Keyboard shortcuts

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