Documentation ¶
Index ¶
- Constants
- Variables
- func GroupLogsByStatus(list []Log) (l map[uint]LogsList)
- type CreateParams
- type Func
- type IRepository
- type IService
- type Log
- type LogsList
- type LogsSlice
- type Migration
- type MigrationsList
- type QueryCondition
- type Service
- func (s Service) Create(ctx context.Context, wr io.Writer, p CreateParams) (err error)
- func (s Service) CreateMainFile(ctx context.Context, wr io.Writer) (err error)
- func (s Service) CreateTable(ctx context.Context) error
- func (s Service) Down(ctx context.Context, ms MigrationsList, quantity int) error
- func (s Service) Last(ctx context.Context) (*Log, error)
- func (s Service) List(ctx context.Context) ([]Log, error)
- func (s Service) NewEntity() *Log
- func (s Service) Query(ctx context.Context, offset, limit uint) ([]Log, error)
- func (s Service) Redo(ctx context.Context, ms MigrationsList) error
- func (s Service) Up(ctx context.Context, ms MigrationsList, quantity int) error
- type ServiceTool
- type Transaction
- type WhereCondition
Constants ¶
const ( // TableName const TableName = "dbmigrator_migration" // StatusNotApplied const StatusNotApplied = 0 // StatusApplied const StatusApplied = 1 // StatusError const StatusError = 2 )
const DefaultDownQuantity = 1
DefaultDownQuantity const
const MigrationTypeGo = "go"
MigrationTypeGo - MigrationType gor go
const MigrationTypeSQL = "sql"
MigrationTypeSQL - MigrationType gor SQL
Variables ¶
var MigrationTypes = []interface{}{MigrationTypeSQL, MigrationTypeGo}
MigrationTypes is slice of migration types
var SQLCreateTable string = `CREATE TABLE IF NOT EXISTS public."` + TableName + `" (
id int4 NOT NULL,
status int4 NOT NULL DEFAULT 0,
name varchar(100) NOT NULL,
"time" timestamptz NOT NULL DEFAULT Now(),
CONSTRAINT migration_pkey PRIMARY KEY (id)
);`
SQLCreateTable is the SQL text for creation table
Functions ¶
func GroupLogsByStatus ¶
GroupLogsByStatus groups logs applied/not applied
Types ¶
type CreateParams ¶
CreateParams is struct for params for creation of migration
type IRepository ¶
type IRepository interface { // SetLogger is setter for logger SetLogger(logger app.Logger) // Get returns an entity with the specified ID. //Get(ctx context.Context, id uint) (*Log, error) // Count returns the number of entities. //Count(ctx context.Context) (uint, error) // Query returns the list of entities with the given offset and limit. Query(ctx context.Context, offset, limit uint) ([]Log, error) // QueryTx returns the list of entities with the given offset and limit. QueryTx(ctx context.Context, t Transaction, query *QueryCondition, offset, limit uint) ([]Log, error) // Last retrieves a last record with the specified query condition and limit 1 from the database. Last(ctx context.Context, query *QueryCondition) (*Log, error) // LastTx retrieves a last record with the specified query condition and limit 1 from the database. LastTx(ctx context.Context, t Transaction, query *QueryCondition) (*Log, error) // Create saves a new entity in the storage. //Create(ctx context.Context, entity *Log) error // Update updates an entity with given ID in the storage. //Update(ctx context.Context, entity *Log) error // Delete removes an entity with given ID from the storage. //Delete(ctx context.Context, id uint) error // ExecSQL executes an user's plain sql ExecSQL(ctx context.Context, sql string) error // ExecSQLTx executes an user's plain sql ExecSQLTx(ctx context.Context, t Transaction, sql string) error // ExecFunc executes an user's func ExecFunc(ctx context.Context, f Func) (err error) // ExecFuncTx executes an user's func ExecFuncTx(ctx context.Context, t Transaction, f Func) (err error) // BeginTx begins a transaction BeginTx(ctx context.Context) (Transaction, error) // BatchCreateTx creates a batch of MigrationsLog with transaction BatchCreateTx(ctx context.Context, t Transaction, list LogsList) error // BatchUpdateTx updates a batch of MigrationsLog with transaction BatchUpdateTx(ctx context.Context, t Transaction, list LogsList) error }
IRepository encapsulates the logic to access albums from the data source.
type IService ¶
type IService interface { // NewEntity returns new empty entity NewEntity() *Log // Get returns an entity with given ID //Get(ctx context.Context, id uint) (*Log, error) //First(ctx context.Context, entity *Event) (*Event, error) // Query returns a list with pagination Query(ctx context.Context, offset, limit uint) ([]Log, error) // List entity List(ctx context.Context) ([]Log, error) //Count(ctx context.Context) (uint, error) // Create entity //Create(ctx context.Context, entity *Log) error // Update entity //Update(ctx context.Context, entity *Log) error // Delete entity //Delete(ctx context.Context, id uint) error // CreateTable creates table for migration CreateTable(ctx context.Context) error // Up a list of migrations Up(ctx context.Context, ms MigrationsList, quantity int) error // Down a list of migrations Down(ctx context.Context, ms MigrationsList, quantity int) error // Redo a last migration Redo(ctx context.Context, ms MigrationsList) error // Last returns a last Log Last(ctx context.Context) (*Log, error) // Create creates a file for migration Create(ctx context.Context, wr io.Writer, p CreateParams) (err error) // Create creates a main file for migrations execution CreateMainFile(ctx context.Context, wr io.Writer) (err error) }
IService encapsulates usecase logic for event.
type LogsList ¶
LogsList is a map of Log entities
func MigrationsLogsFilterExceptByKeys ¶
MigrationsLogsFilterExceptByKeys returns LogsList with all entities from sourceList other than those represented in exceptList
func MigrationsLogsFilterExistsByKeys ¶
MigrationsLogsFilterExistsByKeys returns LogsList with all entities from sourceList that represented in existList
type LogsSlice ¶
type LogsSlice []Log
LogsSlice is a slice of Log entities
type MigrationsList ¶
MigrationsList ia a map of Migration
func MigrationsListFilterExceptByKeys ¶
func MigrationsListFilterExceptByKeys(sourceList MigrationsList, exceptList LogsList) (l MigrationsList)
MigrationsListFilterExceptByKeys returns MigrationsList with all entities from sourceList other than those represented in exceptList
func MigrationsListFilterExistsByKeys ¶
func MigrationsListFilterExistsByKeys(sourceList MigrationsList, existList LogsList) (l MigrationsList)
MigrationsListFilterExistsByKeys returns MigrationsList with all entities from sourceList that represented in existList
type QueryCondition ¶
type QueryCondition struct {
Where *WhereCondition
}
QueryCondition struct for defining a query condition
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service stgruct
func NewService ¶
func NewService(repo IRepository, logger app.Logger) *Service
NewService creates a new Service.
func (Service) CreateMainFile ¶
CreateMainFile here is dummy. Redefined in ServiceTool.
func (Service) CreateTable ¶
CreateTable creates table for migration
type ServiceTool ¶
type ServiceTool struct {
*Service
}
ServiceTool is the service for DBMigrator as a tool
func NewServiceTool ¶
func NewServiceTool(is IService) (*ServiceTool, error)
NewServiceTool creates a new ServiceTool.
func (ServiceTool) Create ¶
func (s ServiceTool) Create(ctx context.Context, wr io.Writer, p CreateParams) (err error)
Create creates a file for migration
func (ServiceTool) CreateMainFile ¶
CreateMainFile creates a main file for migrations execution
type Transaction ¶
type Transaction interface { // Commit a transaction Commit() error // Rollback a transaction Rollback() error }
Transaction for operations in domain level