resource

package
v1.0.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(flags *Flags, config *raiden.Config) error

Migrate resource :

[ ] migrate table

[x] create table name, schema and columns
[x] create table rls enable
[x] create table rls force
[x] create table with primary key
[x] create table with relation (ordered table by relation)
[x] create table with acl (rls)
[x] delete table (cascade)
[x] update table name, schema
[x] update table rls enable
[x] update table rls force
[x] update table with relation - create, update and delete (ordered table by relation)
[x] create table with acl (rls), for now all rls outside manage from raiden will be delete
[x] update table column add new column
[x] update table column delete column
[x] update table column set default schema
[x] update table column set set data type
[x] update table column set unique column
[x] update table column set nullable

[ ] migrate role

[x] create new role
[x] create role with connection limit
[x] create role with inherit
[ ] create role with is replicate - unsupported now because need superuser role
[ ] create role with is super user - unsupported now because need superuser role
[x] create role with can bypass rls, can create db, can create role, can login
[x] create role with valid until
[x] delete role
[ ] update name
[x] update connection limit
[x] update inherit
[ ] update is replicate
[ ] update is super user
[x] update can bypass rls
[x] update can create db
[x] update can create role
[x] update can login
[x] update valid until

[x] migrate function (Rpc)

[x] migrate storage

[ ] create new storage
[ ] update storage
[ ] delete storage
[ ] add storage acl
[ ] update storage acl

func FindResource

func FindResource[T any](data []T, input generator.GenerateInput, findFunc func(item T, inputData generator.GenerateInput) bool) (item T, found bool)

func Import

func Import(flags *Flags, config *raiden.Config) error

List of import resource [x] import table, relation, column specification and acl [x] import role [x] import function [x] import storage

func ImportDecorateFunc

func ImportDecorateFunc[T any](data []T, findFunc func(T, generator.GenerateInput) bool, stateChan chan any) generator.GenerateFn

func ListenApplyResource

func ListenApplyResource(projectPath string, resourceState *ResourceState, stateChan chan any) (done chan error)

func ListenImportResource

func ListenImportResource(resourceState *ResourceState, stateChan chan any) (done chan error)

func MigrateResource

func MigrateResource(config *raiden.Config, importState *ResourceState, projectPath string, resource *MigrateData) (errors []error)

func PreRun

func PreRun(projectPath string) error

func PrintDiff

func PrintDiff(resource string, supabaseResource, appResource interface{}, prefix string)

--- Print diff -----

func PrintDiffDetail

func PrintDiffDetail(resource, prefix string, attribute string, spValue, appValue string)

func RegisterModels

func RegisterModels(list ...any)

func RegisterRole

func RegisterRole(list ...raiden.Role)

func RegisterRpc

func RegisterRpc(list ...raiden.Rpc)

func RegisterStorages

func RegisterStorages(list ...raiden.Bucket)

Types

type CompareDiffResult

type CompareDiffResult[T any, D any] struct {
	Name           string
	SourceResource T
	TargetResource T
	DiffItems      D
	IsConflict     bool
}

func ComparePolicies

func ComparePolicies(sourcePolicies, targetPolicies []objects.Policy) (diffResult []CompareDiffResult[objects.Policy, objects.UpdatePolicyParam])

func CompareRoleImportMode

func CompareRoleImportMode(source, target objects.Role) (diffResult CompareDiffResult[objects.Role, objects.UpdateRoleParam], err error)

func CompareRoles

func CompareRoles(sourceRole, targetRole []objects.Role, mode CompareMode) (diffResult []CompareDiffResult[objects.Role, objects.UpdateRoleParam], err error)

func CompareRpcFunctions

func CompareRpcFunctions(sourceFn []objects.Function, targetFn []objects.Function) (diffResult []CompareDiffResult[objects.Function, any], err error)

func CompareStorage

func CompareStorage(sourceStorage, targetStorage []objects.Bucket) (diffResult []CompareDiffResult[objects.Bucket, objects.UpdateBucketParam], err error)

func CompareTables

func CompareTables(sourceTable, targetTable []objects.Table, mode CompareMode) (diffResult []CompareDiffResult[objects.Table, objects.UpdateTableParam], err error)

CompareTables is function for find different table configuration between supabase and app

for CompareModeImport source table is supabase table and target table is app table for CompareModeApply source table is app table and target table is supabase table

type CompareMode

type CompareMode string
const (
	CompareModeImport CompareMode = "import"
	CompareModeApply  CompareMode = "apply"
)

type Flags

type Flags struct {
	ProjectPath   string
	RpcOnly       bool
	RolesOnly     bool
	ModelsOnly    bool
	StorageOnly   bool
	AllowedSchema string
	Verbose       bool
	Generate      generate.Flags
}

Flags is struct to binding options when import and apply is run binart

func (*Flags) All

func (f *Flags) All() bool

LoadAll is function to check is all resource need to import or apply

func (Flags) CheckAndActivateDebug

func (f Flags) CheckAndActivateDebug(cmd *cobra.Command) bool

type ManyToManyTable

type ManyToManyTable struct {
	Table      string
	Schema     string
	PivotTable string
	PrimaryKey string
	ForeignKey string
}

---- build table relation for generated -----

type MapRelations

type MapRelations map[string][]*state.Relation

---- build table relation for generated -----

type MapTable

type MapTable map[string]*objects.Table

----- Convert array of table to map table -----

type MigrateActionFunc

type MigrateActionFunc[T, D any] struct {
	CreateFunc MigrateCreateFunc[T]
	UpdateFunc MigrateUpdateFunc[T, D]
	DeleteFunc MigrateDeleteFunc[T]
}

type MigrateCreateFunc

type MigrateCreateFunc[T any] func(cfg *raiden.Config, param T) (response T, err error)

type MigrateDeleteFunc

type MigrateDeleteFunc[T any] func(cfg *raiden.Config, param T) (err error)

type MigrateFunc

type MigrateFunc[T, D any] func(param MigrateFuncParam[T, D]) error

type MigrateFuncParam

type MigrateFuncParam[T, D any] struct {
	Config      *raiden.Config
	StateChan   chan any
	Data        MigrateItem[T, D]
	ActionFuncs MigrateActionFunc[T, D]
}

type MigrateItem

type MigrateItem[T, D any] struct {
	Type           MigrateType
	NewData        T
	OldData        T
	MigrationItems D
}

type MigrateTableNode

type MigrateTableNode struct {
	Level         int
	MigratedItems []MigrateItem[objects.Table, objects.UpdateTableParam]
	Child         *MigrateTableNode
}

type MigrateType

type MigrateType string
const (
	MigrateTypeIgnore MigrateType = "ignore"
	MigrateTypeCreate MigrateType = "create"
	MigrateTypeUpdate MigrateType = "update"
	MigrateTypeDelete MigrateType = "delete"
)

type MigrateUpdateFunc

type MigrateUpdateFunc[T, D any] func(cfg *raiden.Config, param T, items D) (err error)

type Resource

type Resource struct {
	Tables    []objects.Table
	Policies  objects.Policies
	Roles     []objects.Role
	Functions []objects.Function
	Storages  []objects.Bucket
}

func Load

func Load(flags *Flags, cfg *raiden.Config) (*Resource, error)

The Load function loads resources based on the provided flags and project ID, and returns a resource objects or an error.

type ResourceState

type ResourceState struct {
	State      state.State
	NeedUpdate bool
	Mutex      sync.RWMutex
}

func (*ResourceState) AddRole

func (s *ResourceState) AddRole(role state.RoleState)

func (*ResourceState) AddRpc

func (s *ResourceState) AddRpc(rpc state.RpcState)

func (*ResourceState) AddStorage

func (s *ResourceState) AddStorage(storage state.StorageState)

func (*ResourceState) AddTable

func (s *ResourceState) AddTable(table state.TableState)

func (*ResourceState) DeleteRole

func (s *ResourceState) DeleteRole(roleId int)

func (*ResourceState) DeleteRpc

func (s *ResourceState) DeleteRpc(rpcId int)

func (*ResourceState) DeleteStorage

func (s *ResourceState) DeleteStorage(storageId string)

func (*ResourceState) DeleteTable

func (s *ResourceState) DeleteTable(tableId int)

func (*ResourceState) FindRole

func (s *ResourceState) FindRole(roleId int) (index int, roleState state.RoleState, found bool)

func (*ResourceState) FindRpc

func (s *ResourceState) FindRpc(rpcId int) (index int, rpcState state.RpcState, found bool)

func (*ResourceState) FindStorage

func (s *ResourceState) FindStorage(storageId string) (index int, storageState state.StorageState, found bool)

func (*ResourceState) FindTable

func (s *ResourceState) FindTable(tableId int) (index int, tableState state.TableState, found bool)

func (*ResourceState) Persist

func (s *ResourceState) Persist() error

func (*ResourceState) UpdateRole

func (s *ResourceState) UpdateRole(index int, state state.RoleState)

func (*ResourceState) UpdateRpc

func (s *ResourceState) UpdateRpc(index int, state state.RpcState)

func (*ResourceState) UpdateStorage

func (s *ResourceState) UpdateStorage(index int, state state.StorageState)

func (*ResourceState) UpdateTable

func (s *ResourceState) UpdateTable(index int, state state.TableState)

Jump to

Keyboard shortcuts

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