feat: kubesphere 4.0 (#6115)
* feat: kubesphere 4.0 Signed-off-by: ci-bot <ci-bot@kubesphere.io> * feat: kubesphere 4.0 Signed-off-by: ci-bot <ci-bot@kubesphere.io> --------- Signed-off-by: ci-bot <ci-bot@kubesphere.io> Co-authored-by: ks-ci-bot <ks-ci-bot@example.com> Co-authored-by: joyceliu <joyceliu@yunify.com>
This commit is contained in:
committed by
GitHub
parent
b5015ec7b9
commit
447a51f08b
2
vendor/github.com/rubenv/sql-migrate/.gitignore
generated
vendored
2
vendor/github.com/rubenv/sql-migrate/.gitignore
generated
vendored
@@ -5,3 +5,5 @@
|
||||
|
||||
/sql-migrate/test.db
|
||||
/test.db
|
||||
.vscode/
|
||||
bin/
|
||||
|
||||
98
vendor/github.com/rubenv/sql-migrate/.golangci.yaml
generated
vendored
Normal file
98
vendor/github.com/rubenv/sql-migrate/.golangci.yaml
generated
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
linters-settings:
|
||||
gocritic:
|
||||
disabled-checks:
|
||||
- ifElseChain
|
||||
goimports:
|
||||
local-prefixes: github.com/rubenv/sql-migrate
|
||||
govet:
|
||||
enable-all: true
|
||||
disable:
|
||||
- fieldalignment
|
||||
depguard:
|
||||
list-type: blacklist
|
||||
include-go-root: true
|
||||
include-go-std-lib: true
|
||||
exhaustive:
|
||||
default-signifies-exhaustive: true
|
||||
nolintlint:
|
||||
allow-unused: false
|
||||
allow-leading-space: false
|
||||
allow-no-explanation:
|
||||
- depguard
|
||||
require-explanation: true
|
||||
require-specific: true
|
||||
revive:
|
||||
enable-all-rules: false
|
||||
rules:
|
||||
- name: atomic
|
||||
- name: blank-imports
|
||||
- name: bool-literal-in-expr
|
||||
- name: call-to-gc
|
||||
- name: constant-logical-expr
|
||||
- name: context-as-argument
|
||||
- name: context-keys-type
|
||||
- name: dot-imports
|
||||
- name: duplicated-imports
|
||||
- name: empty-block
|
||||
- name: empty-lines
|
||||
- name: error-naming
|
||||
- name: error-return
|
||||
- name: error-strings
|
||||
- name: errorf
|
||||
- name: exported
|
||||
- name: identical-branches
|
||||
- name: imports-blacklist
|
||||
- name: increment-decrement
|
||||
- name: indent-error-flow
|
||||
- name: modifies-parameter
|
||||
- name: modifies-value-receiver
|
||||
- name: package-comments
|
||||
- name: range
|
||||
- name: range-val-address
|
||||
- name: range-val-in-closure
|
||||
- name: receiver-naming
|
||||
- name: string-format
|
||||
- name: string-of-int
|
||||
- name: struct-tag
|
||||
- name: time-naming
|
||||
- name: unconditional-recursion
|
||||
- name: unexported-naming
|
||||
- name: unexported-return
|
||||
- name: superfluous-else
|
||||
- name: unreachable-code
|
||||
- name: var-declaration
|
||||
- name: waitgroup-by-value
|
||||
- name: unused-receiver
|
||||
- name: unnecessary-stmt
|
||||
- name: unused-parameter
|
||||
run:
|
||||
tests: true
|
||||
timeout: 1m
|
||||
linters:
|
||||
disable-all: true
|
||||
enable:
|
||||
- asciicheck
|
||||
- depguard
|
||||
- errcheck
|
||||
- exhaustive
|
||||
- gocritic
|
||||
- gofmt
|
||||
- gofumpt
|
||||
- goimports
|
||||
- govet
|
||||
- ineffassign
|
||||
- nolintlint
|
||||
- revive
|
||||
- staticcheck
|
||||
- typecheck
|
||||
- unused
|
||||
- whitespace
|
||||
- errorlint
|
||||
- gosimple
|
||||
- unparam
|
||||
issues:
|
||||
exclude:
|
||||
- 'declaration of "err" shadows declaration at' # Allow shadowing of `err` because it's so common
|
||||
- 'error-strings: error strings should not be capitalized or end with punctuation or a newline'
|
||||
max-same-issues: 10000
|
||||
max-issues-per-linter: 10000
|
||||
33
vendor/github.com/rubenv/sql-migrate/.travis.yml
generated
vendored
33
vendor/github.com/rubenv/sql-migrate/.travis.yml
generated
vendored
@@ -1,33 +0,0 @@
|
||||
language: go
|
||||
|
||||
sudo: false
|
||||
|
||||
go:
|
||||
- "1.13"
|
||||
- "1.14"
|
||||
- "1.15"
|
||||
- "1.16"
|
||||
|
||||
services:
|
||||
- mysql
|
||||
- postgresql
|
||||
|
||||
before_install:
|
||||
- mysql -e "CREATE DATABASE IF NOT EXISTS test;" -uroot
|
||||
- mysql -e "CREATE DATABASE IF NOT EXISTS test_env;" -uroot
|
||||
- psql -c "CREATE DATABASE test;" -U postgres
|
||||
|
||||
install:
|
||||
- go get -t ./...
|
||||
- go install ./...
|
||||
- go get -u github.com/kisielk/errcheck
|
||||
|
||||
script:
|
||||
- CGO_ENABLED=0 go build -v .
|
||||
- go test -v ./...
|
||||
- bash test-integration/postgres.sh
|
||||
- bash test-integration/mysql.sh
|
||||
- bash test-integration/mysql-flag.sh
|
||||
- bash test-integration/mysql-env.sh
|
||||
- bash test-integration/sqlite.sh
|
||||
- errcheck ./...
|
||||
2
vendor/github.com/rubenv/sql-migrate/Dockerfile
generated
vendored
2
vendor/github.com/rubenv/sql-migrate/Dockerfile
generated
vendored
@@ -1,4 +1,4 @@
|
||||
ARG GO_VERSION=1.16.2
|
||||
ARG GO_VERSION=1.20.6
|
||||
ARG ALPINE_VERSION=3.12
|
||||
|
||||
### Vendor
|
||||
|
||||
11
vendor/github.com/rubenv/sql-migrate/Makefile
generated
vendored
Normal file
11
vendor/github.com/rubenv/sql-migrate/Makefile
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
.PHONY: test lint build
|
||||
|
||||
test:
|
||||
go test ./...
|
||||
|
||||
lint:
|
||||
golangci-lint run --fix --config .golangci.yaml
|
||||
|
||||
build:
|
||||
mkdir -p bin
|
||||
go build -o ./bin/sql-migrate ./sql-migrate
|
||||
84
vendor/github.com/rubenv/sql-migrate/README.md
generated
vendored
84
vendor/github.com/rubenv/sql-migrate/README.md
generated
vendored
@@ -2,20 +2,19 @@
|
||||
|
||||
> SQL Schema migration tool for [Go](https://golang.org/). Based on [gorp](https://github.com/go-gorp/gorp) and [goose](https://bitbucket.org/liamstask/goose).
|
||||
|
||||
[](https://travis-ci.org/rubenv/sql-migrate) [](https://godoc.org/github.com/rubenv/sql-migrate)
|
||||
|
||||
Using [modl](https://github.com/jmoiron/modl)? Check out [modl-migrate](https://github.com/rubenv/modl-migrate).
|
||||
[](https://github.com/rubenv/sql-migrate/actions/workflows/test.yml) [](https://pkg.go.dev/github.com/rubenv/sql-migrate)
|
||||
|
||||
## Features
|
||||
|
||||
* Usable as a CLI tool or as a library
|
||||
* Supports SQLite, PostgreSQL, MySQL, MSSQL and Oracle databases (through [gorp](https://github.com/go-gorp/gorp))
|
||||
* Can embed migrations into your application
|
||||
* Migrations are defined with SQL for full flexibility
|
||||
* Atomic migrations
|
||||
* Up/down migrations to allow rollback
|
||||
* Supports multiple database types in one project
|
||||
* Works great with other libraries such as [sqlx](https://jmoiron.github.io/sqlx/)
|
||||
- Usable as a CLI tool or as a library
|
||||
- Supports SQLite, PostgreSQL, MySQL, MSSQL and Oracle databases (through [gorp](https://github.com/go-gorp/gorp))
|
||||
- Can embed migrations into your application
|
||||
- Migrations are defined with SQL for full flexibility
|
||||
- Atomic migrations
|
||||
- Up/down migrations to allow rollback
|
||||
- Supports multiple database types in one project
|
||||
- Works great with other libraries such as [sqlx](https://jmoiron.github.io/sqlx/)
|
||||
- Supported on go1.13+
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -24,7 +23,9 @@ To install the library and command line program, use the following:
|
||||
```bash
|
||||
go get -v github.com/rubenv/sql-migrate/...
|
||||
```
|
||||
|
||||
For Go version from 1.18, use:
|
||||
|
||||
```bash
|
||||
go install github.com/rubenv/sql-migrate/...@latest
|
||||
```
|
||||
@@ -49,15 +50,15 @@ Each command requires a configuration file (which defaults to `dbconfig.yml`, bu
|
||||
|
||||
```yml
|
||||
development:
|
||||
dialect: sqlite3
|
||||
datasource: test.db
|
||||
dir: migrations/sqlite3
|
||||
dialect: sqlite3
|
||||
datasource: test.db
|
||||
dir: migrations/sqlite3
|
||||
|
||||
production:
|
||||
dialect: postgres
|
||||
datasource: dbname=myapp sslmode=disable
|
||||
dir: migrations/postgres
|
||||
table: migrations
|
||||
dialect: postgres
|
||||
datasource: dbname=myapp sslmode=disable
|
||||
dir: migrations/postgres
|
||||
table: migrations
|
||||
```
|
||||
|
||||
(See more examples for different set ups [here](test-integration/dbconfig.yml))
|
||||
@@ -67,10 +68,10 @@ This may be useful if one doesn't want to store credentials in file:
|
||||
|
||||
```yml
|
||||
production:
|
||||
dialect: postgres
|
||||
datasource: host=prodhost dbname=proddb user=${DB_USER} password=${DB_PASSWORD} sslmode=required
|
||||
dir: migrations
|
||||
table: migrations
|
||||
dialect: postgres
|
||||
datasource: host=prodhost dbname=proddb user=${DB_USER} password=${DB_PASSWORD} sslmode=require
|
||||
dir: migrations
|
||||
table: migrations
|
||||
```
|
||||
|
||||
The `table` setting is optional and will default to `gorp_migrations`.
|
||||
@@ -90,12 +91,13 @@ Options:
|
||||
-config=dbconfig.yml Configuration file to use.
|
||||
-env="development" Environment.
|
||||
-limit=0 Limit the number of migrations (0 = unlimited).
|
||||
-version Run migrate up to a specific version, eg: the version number of migration 1_initial.sql is 1.
|
||||
-dryrun Don't apply migrations, just print them.
|
||||
```
|
||||
|
||||
The `new` command creates a new empty migration template using the following pattern `<current time>-<name>.sql`.
|
||||
|
||||
The `up` command applies all available migrations. By contrast, `down` will only apply one migration by default. This behavior can be changed for both by using the `-limit` parameter.
|
||||
The `up` command applies all available migrations. By contrast, `down` will only apply one migration by default. This behavior can be changed for both by using the `-limit` parameter, and the `-version` parameter. Note `-version` has higher priority than `-limit` if you try to use them both.
|
||||
|
||||
The `redo` command will unapply the last migration and reapply it. This is useful during development, when you're writing migrations.
|
||||
|
||||
@@ -112,6 +114,7 @@ $ sql-migrate status
|
||||
```
|
||||
|
||||
#### Running Test Integrations
|
||||
|
||||
You can see how to run setups for different setups by executing the `.sh` files in [test-integration](test-integration/)
|
||||
|
||||
```bash
|
||||
@@ -126,15 +129,16 @@ If you are using MySQL, you must append `?parseTime=true` to the `datasource` co
|
||||
|
||||
```yml
|
||||
production:
|
||||
dialect: mysql
|
||||
datasource: root@/dbname?parseTime=true
|
||||
dir: migrations/mysql
|
||||
table: migrations
|
||||
dialect: mysql
|
||||
datasource: root@/dbname?parseTime=true
|
||||
dir: migrations/mysql
|
||||
table: migrations
|
||||
```
|
||||
|
||||
See [here](https://github.com/go-sql-driver/mysql#parsetime) for more information.
|
||||
|
||||
### Oracle (oci8)
|
||||
|
||||
Oracle Driver is [oci8](https://github.com/mattn/go-oci8), it is not pure Go code and relies on Oracle Office Client ([Instant Client](https://www.oracle.com/database/technologies/instant-client/downloads.html)), more detailed information is in the [oci8 repo](https://github.com/mattn/go-oci8).
|
||||
|
||||
#### Install with Oracle support
|
||||
@@ -147,13 +151,14 @@ go get -tags oracle -v github.com/rubenv/sql-migrate/...
|
||||
|
||||
```yml
|
||||
development:
|
||||
dialect: oci8
|
||||
datasource: user/password@localhost:1521/sid
|
||||
dir: migrations/oracle
|
||||
table: migrations
|
||||
dialect: oci8
|
||||
datasource: user/password@localhost:1521/sid
|
||||
dir: migrations/oracle
|
||||
table: migrations
|
||||
```
|
||||
|
||||
### Oracle (godror)
|
||||
|
||||
Oracle Driver is [godror](https://github.com/godror/godror), it is not pure Go code and relies on Oracle Office Client ([Instant Client](https://www.oracle.com/database/technologies/instant-client/downloads.html)), more detailed information is in the [godror repository](https://github.com/godror/godror).
|
||||
|
||||
#### Install with Oracle support
|
||||
@@ -161,29 +166,31 @@ Oracle Driver is [godror](https://github.com/godror/godror), it is not pure Go c
|
||||
To install the library and command line program, use the following:
|
||||
|
||||
1. Install sql-migrate
|
||||
|
||||
```bash
|
||||
go get -tags godror -v github.com/rubenv/sql-migrate/...
|
||||
```
|
||||
|
||||
2. Download Oracle Office Client(e.g. macos, click [Instant Client](https://www.oracle.com/database/technologies/instant-client/downloads.html) if you are other system)
|
||||
|
||||
```bash
|
||||
wget https://download.oracle.com/otn_software/mac/instantclient/193000/instantclient-basic-macos.x64-19.3.0.0.0dbru.zip
|
||||
```
|
||||
|
||||
3. Configure environment variables `LD_LIBRARY_PATH`
|
||||
|
||||
```
|
||||
export LD_LIBRARY_PATH=your_oracle_office_path/instantclient_19_3
|
||||
```
|
||||
|
||||
```yml
|
||||
development:
|
||||
dialect: godror
|
||||
datasource: user/password@localhost:1521/sid
|
||||
dir: migrations/oracle
|
||||
table: migrations
|
||||
dialect: godror
|
||||
datasource: user/password@localhost:1521/sid
|
||||
dir: migrations/oracle
|
||||
table: migrations
|
||||
```
|
||||
|
||||
|
||||
### As a library
|
||||
|
||||
Import sql-migrate into your application:
|
||||
@@ -254,6 +261,7 @@ Note that `n` can be greater than `0` even if there is an error: any migration t
|
||||
Check [the GoDoc reference](https://godoc.org/github.com/rubenv/sql-migrate) for the full documentation.
|
||||
|
||||
## Writing migrations
|
||||
|
||||
Migrations are defined in SQL files, which contain a set of SQL statements. Special comments are used to distinguish up and down migrations.
|
||||
|
||||
```sql
|
||||
@@ -399,6 +407,10 @@ if err != nil {
|
||||
}
|
||||
```
|
||||
|
||||
## Questions or Feedback?
|
||||
|
||||
You can use Github Issues for feedback or questions.
|
||||
|
||||
## License
|
||||
|
||||
This library is distributed under the [MIT](LICENSE) license.
|
||||
|
||||
31
vendor/github.com/rubenv/sql-migrate/doc.go
generated
vendored
31
vendor/github.com/rubenv/sql-migrate/doc.go
generated
vendored
@@ -1,24 +1,23 @@
|
||||
/*
|
||||
|
||||
SQL Schema migration tool for Go.
|
||||
|
||||
Key features:
|
||||
|
||||
* Usable as a CLI tool or as a library
|
||||
* Supports SQLite, PostgreSQL, MySQL, MSSQL and Oracle databases (through gorp)
|
||||
* Can embed migrations into your application
|
||||
* Migrations are defined with SQL for full flexibility
|
||||
* Atomic migrations
|
||||
* Up/down migrations to allow rollback
|
||||
* Supports multiple database types in one project
|
||||
- Usable as a CLI tool or as a library
|
||||
- Supports SQLite, PostgreSQL, MySQL, MSSQL and Oracle databases (through gorp)
|
||||
- Can embed migrations into your application
|
||||
- Migrations are defined with SQL for full flexibility
|
||||
- Atomic migrations
|
||||
- Up/down migrations to allow rollback
|
||||
- Supports multiple database types in one project
|
||||
|
||||
Installation
|
||||
# Installation
|
||||
|
||||
To install the library and command line program, use the following:
|
||||
|
||||
go get -v github.com/rubenv/sql-migrate/...
|
||||
|
||||
Command-line tool
|
||||
# Command-line tool
|
||||
|
||||
The main command is called sql-migrate.
|
||||
|
||||
@@ -77,7 +76,7 @@ Use the status command to see the state of the applied migrations:
|
||||
| 2_record.sql | no |
|
||||
+---------------+-----------------------------------------+
|
||||
|
||||
MySQL Caveat
|
||||
# MySQL Caveat
|
||||
|
||||
If you are using MySQL, you must append ?parseTime=true to the datasource configuration. For example:
|
||||
|
||||
@@ -89,7 +88,7 @@ If you are using MySQL, you must append ?parseTime=true to the datasource config
|
||||
|
||||
See https://github.com/go-sql-driver/mysql#parsetime for more information.
|
||||
|
||||
Library
|
||||
# Library
|
||||
|
||||
Import sql-migrate into your application:
|
||||
|
||||
@@ -137,7 +136,7 @@ Note that n can be greater than 0 even if there is an error: any migration that
|
||||
|
||||
The full set of capabilities can be found in the API docs below.
|
||||
|
||||
Writing migrations
|
||||
# Writing migrations
|
||||
|
||||
Migrations are defined in SQL files, which contain a set of SQL statements. Special comments are used to distinguish up and down migrations.
|
||||
|
||||
@@ -183,7 +182,7 @@ Normally each migration is run within a transaction in order to guarantee that i
|
||||
-- +migrate Down
|
||||
DROP INDEX people_unique_id_idx;
|
||||
|
||||
Embedding migrations with packr
|
||||
# Embedding migrations with packr
|
||||
|
||||
If you like your Go applications self-contained (that is: a single binary): use packr (https://github.com/gobuffalo/packr) to embed the migration files.
|
||||
|
||||
@@ -202,7 +201,7 @@ If you already have a box and would like to use a subdirectory:
|
||||
Dir: "./migrations",
|
||||
}
|
||||
|
||||
Embedding migrations with bindata
|
||||
# Embedding migrations with bindata
|
||||
|
||||
As an alternative, but slightly less maintained, you can use bindata (https://github.com/shuLhan/go-bindata) to embed the migration files.
|
||||
|
||||
@@ -226,7 +225,7 @@ Both Asset and AssetDir are functions provided by bindata.
|
||||
|
||||
Then proceed as usual.
|
||||
|
||||
Extending
|
||||
# Extending
|
||||
|
||||
Adding a new migration source means implementing MigrationSource.
|
||||
|
||||
|
||||
146
vendor/github.com/rubenv/sql-migrate/migrate.go
generated
vendored
146
vendor/github.com/rubenv/sql-migrate/migrate.go
generated
vendored
@@ -2,6 +2,7 @@ package migrate
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -16,6 +17,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-gorp/gorp/v3"
|
||||
|
||||
"github.com/rubenv/sql-migrate/sqlparse"
|
||||
)
|
||||
|
||||
@@ -182,25 +184,26 @@ type OracleDialect struct {
|
||||
gorp.OracleDialect
|
||||
}
|
||||
|
||||
func (d OracleDialect) IfTableNotExists(command, schema, table string) string {
|
||||
func (OracleDialect) IfTableNotExists(command, _, _ string) string {
|
||||
return command
|
||||
}
|
||||
|
||||
func (d OracleDialect) IfSchemaNotExists(command, schema string) string {
|
||||
func (OracleDialect) IfSchemaNotExists(command, _ string) string {
|
||||
return command
|
||||
}
|
||||
|
||||
func (d OracleDialect) IfTableExists(command, schema, table string) string {
|
||||
func (OracleDialect) IfTableExists(command, _, _ string) string {
|
||||
return command
|
||||
}
|
||||
|
||||
var MigrationDialects = map[string]gorp.Dialect{
|
||||
"sqlite3": gorp.SqliteDialect{},
|
||||
"postgres": gorp.PostgresDialect{},
|
||||
"mysql": gorp.MySQLDialect{Engine: "InnoDB", Encoding: "UTF8"},
|
||||
"mssql": gorp.SqlServerDialect{},
|
||||
"oci8": OracleDialect{},
|
||||
"godror": OracleDialect{},
|
||||
"sqlite3": gorp.SqliteDialect{},
|
||||
"postgres": gorp.PostgresDialect{},
|
||||
"mysql": gorp.MySQLDialect{Engine: "InnoDB", Encoding: "UTF8"},
|
||||
"mssql": gorp.SqlServerDialect{},
|
||||
"oci8": OracleDialect{},
|
||||
"godror": OracleDialect{},
|
||||
"snowflake": gorp.SnowflakeDialect{},
|
||||
}
|
||||
|
||||
type MigrationSource interface {
|
||||
@@ -285,13 +288,13 @@ func migrationFromFile(dir http.FileSystem, root string, info os.FileInfo) (*Mig
|
||||
path := path.Join(root, info.Name())
|
||||
file, err := dir.Open(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error while opening %s: %s", info.Name(), err)
|
||||
return nil, fmt.Errorf("Error while opening %s: %w", info.Name(), err)
|
||||
}
|
||||
defer func() { _ = file.Close() }()
|
||||
|
||||
migration, err := ParseMigration(info.Name(), file)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error while parsing %s: %s", info.Name(), err)
|
||||
return nil, fmt.Errorf("Error while parsing %s: %w", info.Name(), err)
|
||||
}
|
||||
return migration, nil
|
||||
}
|
||||
@@ -405,7 +408,7 @@ func ParseMigration(id string, r io.ReadSeeker) (*Migration, error) {
|
||||
|
||||
parsed, err := sqlparse.ParseMigration(r)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error parsing migration (%s): %s", id, err)
|
||||
return nil, fmt.Errorf("Error parsing migration (%s): %w", id, err)
|
||||
}
|
||||
|
||||
m.Up = parsed.UpStatements
|
||||
@@ -427,12 +430,24 @@ type SqlExecutor interface {
|
||||
//
|
||||
// Returns the number of applied migrations.
|
||||
func Exec(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection) (int, error) {
|
||||
return ExecMax(db, dialect, m, dir, 0)
|
||||
return ExecMaxContext(context.Background(), db, dialect, m, dir, 0)
|
||||
}
|
||||
|
||||
// Returns the number of applied migrations.
|
||||
func (ms MigrationSet) Exec(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection) (int, error) {
|
||||
return ms.ExecMax(db, dialect, m, dir, 0)
|
||||
return ms.ExecMaxContext(context.Background(), db, dialect, m, dir, 0)
|
||||
}
|
||||
|
||||
// Execute a set of migrations with an input context.
|
||||
//
|
||||
// Returns the number of applied migrations.
|
||||
func ExecContext(ctx context.Context, db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection) (int, error) {
|
||||
return ExecMaxContext(ctx, db, dialect, m, dir, 0)
|
||||
}
|
||||
|
||||
// Returns the number of applied migrations.
|
||||
func (ms MigrationSet) ExecContext(ctx context.Context, db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection) (int, error) {
|
||||
return ms.ExecMaxContext(ctx, db, dialect, m, dir, 0)
|
||||
}
|
||||
|
||||
// Execute a set of migrations
|
||||
@@ -444,25 +459,78 @@ func ExecMax(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirecti
|
||||
return migSet.ExecMax(db, dialect, m, dir, max)
|
||||
}
|
||||
|
||||
// Execute a set of migrations with an input context.
|
||||
//
|
||||
// Will apply at most `max` migrations. Pass 0 for no limit (or use Exec).
|
||||
//
|
||||
// Returns the number of applied migrations.
|
||||
func ExecMaxContext(ctx context.Context, db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, max int) (int, error) {
|
||||
return migSet.ExecMaxContext(ctx, db, dialect, m, dir, max)
|
||||
}
|
||||
|
||||
// Execute a set of migrations
|
||||
//
|
||||
// Will apply at the target `version` of migration. Cannot be a negative value.
|
||||
//
|
||||
// Returns the number of applied migrations.
|
||||
func ExecVersion(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, version int64) (int, error) {
|
||||
return ExecVersionContext(context.Background(), db, dialect, m, dir, version)
|
||||
}
|
||||
|
||||
// Execute a set of migrations with an input context.
|
||||
//
|
||||
// Will apply at the target `version` of migration. Cannot be a negative value.
|
||||
//
|
||||
// Returns the number of applied migrations.
|
||||
func ExecVersionContext(ctx context.Context, db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, version int64) (int, error) {
|
||||
if version < 0 {
|
||||
return 0, fmt.Errorf("target version %d should not be negative", version)
|
||||
}
|
||||
return migSet.ExecVersionContext(ctx, db, dialect, m, dir, version)
|
||||
}
|
||||
|
||||
// Returns the number of applied migrations.
|
||||
func (ms MigrationSet) ExecMax(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, max int) (int, error) {
|
||||
return ms.ExecMaxContext(context.Background(), db, dialect, m, dir, max)
|
||||
}
|
||||
|
||||
// Returns the number of applied migrations, but applies with an input context.
|
||||
func (ms MigrationSet) ExecMaxContext(ctx context.Context, db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, max int) (int, error) {
|
||||
migrations, dbMap, err := ms.PlanMigration(db, dialect, m, dir, max)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return ms.applyMigrations(ctx, dir, migrations, dbMap)
|
||||
}
|
||||
|
||||
// Apply migrations
|
||||
// Returns the number of applied migrations.
|
||||
func (ms MigrationSet) ExecVersion(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, version int64) (int, error) {
|
||||
return ms.ExecVersionContext(context.Background(), db, dialect, m, dir, version)
|
||||
}
|
||||
|
||||
func (ms MigrationSet) ExecVersionContext(ctx context.Context, db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, version int64) (int, error) {
|
||||
migrations, dbMap, err := ms.PlanMigrationToVersion(db, dialect, m, dir, version)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return ms.applyMigrations(ctx, dir, migrations, dbMap)
|
||||
}
|
||||
|
||||
// Applies the planned migrations and returns the number of applied migrations.
|
||||
func (MigrationSet) applyMigrations(ctx context.Context, dir MigrationDirection, migrations []*PlannedMigration, dbMap *gorp.DbMap) (int, error) {
|
||||
applied := 0
|
||||
for _, migration := range migrations {
|
||||
var executor SqlExecutor
|
||||
var err error
|
||||
|
||||
if migration.DisableTransaction {
|
||||
executor = dbMap
|
||||
executor = dbMap.WithContext(ctx)
|
||||
} else {
|
||||
executor, err = dbMap.Begin()
|
||||
e, err := dbMap.Begin()
|
||||
if err != nil {
|
||||
return applied, newTxError(migration, err)
|
||||
}
|
||||
executor = e.WithContext(ctx)
|
||||
}
|
||||
|
||||
for _, stmt := range migration.Queries {
|
||||
@@ -524,7 +592,23 @@ func PlanMigration(db *sql.DB, dialect string, m MigrationSource, dir MigrationD
|
||||
return migSet.PlanMigration(db, dialect, m, dir, max)
|
||||
}
|
||||
|
||||
// Plan a migration to version.
|
||||
func PlanMigrationToVersion(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, version int64) ([]*PlannedMigration, *gorp.DbMap, error) {
|
||||
return migSet.PlanMigrationToVersion(db, dialect, m, dir, version)
|
||||
}
|
||||
|
||||
// Plan a migration.
|
||||
func (ms MigrationSet) PlanMigration(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, max int) ([]*PlannedMigration, *gorp.DbMap, error) {
|
||||
return ms.planMigrationCommon(db, dialect, m, dir, max, -1)
|
||||
}
|
||||
|
||||
// Plan a migration to version.
|
||||
func (ms MigrationSet) PlanMigrationToVersion(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, version int64) ([]*PlannedMigration, *gorp.DbMap, error) {
|
||||
return ms.planMigrationCommon(db, dialect, m, dir, 0, version)
|
||||
}
|
||||
|
||||
// A common method to plan a migration.
|
||||
func (ms MigrationSet) planMigrationCommon(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirection, max int, version int64) ([]*PlannedMigration, *gorp.DbMap, error) {
|
||||
dbMap, err := ms.getMigrationDbMap(db, dialect)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -581,11 +665,27 @@ func (ms MigrationSet) PlanMigration(db *sql.DB, dialect string, m MigrationSour
|
||||
// Figure out which migrations to apply
|
||||
toApply := ToApply(migrations, record.Id, dir)
|
||||
toApplyCount := len(toApply)
|
||||
if max > 0 && max < toApplyCount {
|
||||
|
||||
if version >= 0 {
|
||||
targetIndex := 0
|
||||
for targetIndex < len(toApply) {
|
||||
tempVersion := toApply[targetIndex].VersionInt()
|
||||
if dir == Up && tempVersion > version || dir == Down && tempVersion < version {
|
||||
return nil, nil, newPlanError(&Migration{}, fmt.Errorf("unknown migration with version id %d in database", version).Error())
|
||||
}
|
||||
if tempVersion == version {
|
||||
toApplyCount = targetIndex + 1
|
||||
break
|
||||
}
|
||||
targetIndex++
|
||||
}
|
||||
if targetIndex == len(toApply) {
|
||||
return nil, nil, newPlanError(&Migration{}, fmt.Errorf("unknown migration with version id %d in database", version).Error())
|
||||
}
|
||||
} else if max > 0 && max < toApplyCount {
|
||||
toApplyCount = max
|
||||
}
|
||||
for _, v := range toApply[0:toApplyCount] {
|
||||
|
||||
if dir == Up {
|
||||
result = append(result, &PlannedMigration{
|
||||
Migration: v,
|
||||
@@ -655,7 +755,7 @@ func SkipMax(db *sql.DB, dialect string, m MigrationSource, dir MigrationDirecti
|
||||
|
||||
// Filter a slice of migrations into ones that should be applied.
|
||||
func ToApply(migrations []*Migration, current string, direction MigrationDirection) []*Migration {
|
||||
var index = -1
|
||||
index := -1
|
||||
if current != "" {
|
||||
for index < len(migrations)-1 {
|
||||
index++
|
||||
@@ -744,22 +844,20 @@ func (ms MigrationSet) getMigrationDbMap(db *sql.DB, dialect string) (*gorp.DbMa
|
||||
|
||||
Make sure that the parseTime option is supplied to your database connection.
|
||||
Check https://github.com/go-sql-driver/mysql#parsetime for more info.`)
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Create migration database map
|
||||
dbMap := &gorp.DbMap{Db: db, Dialect: d}
|
||||
table := dbMap.AddTableWithNameAndSchema(MigrationRecord{}, ms.SchemaName, ms.getTableName()).SetKeys(false, "Id")
|
||||
//dbMap.TraceOn("", log.New(os.Stdout, "migrate: ", log.Lmicroseconds))
|
||||
|
||||
if dialect == "oci8" || dialect == "godror" {
|
||||
table.ColMap("Id").SetMaxSize(4000)
|
||||
}
|
||||
|
||||
if migSet.DisableCreateTable {
|
||||
if ms.DisableCreateTable {
|
||||
return dbMap, nil
|
||||
}
|
||||
|
||||
|
||||
37
vendor/github.com/rubenv/sql-migrate/sqlparse/sqlparse.go
generated
vendored
37
vendor/github.com/rubenv/sql-migrate/sqlparse/sqlparse.go
generated
vendored
@@ -3,10 +3,8 @@ package sqlparse
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -23,29 +21,26 @@ type ParsedMigration struct {
|
||||
DisableTransactionDown bool
|
||||
}
|
||||
|
||||
var (
|
||||
// LineSeparator can be used to split migrations by an exact line match. This line
|
||||
// will be removed from the output. If left blank, it is not considered. It is defaulted
|
||||
// to blank so you will have to set it manually.
|
||||
// Use case: in MSSQL, it is convenient to separate commands by GO statements like in
|
||||
// SQL Query Analyzer.
|
||||
LineSeparator = ""
|
||||
)
|
||||
// LineSeparator can be used to split migrations by an exact line match. This line
|
||||
// will be removed from the output. If left blank, it is not considered. It is defaulted
|
||||
// to blank so you will have to set it manually.
|
||||
// Use case: in MSSQL, it is convenient to separate commands by GO statements like in
|
||||
// SQL Query Analyzer.
|
||||
var LineSeparator = ""
|
||||
|
||||
func errNoTerminator() error {
|
||||
if len(LineSeparator) == 0 {
|
||||
return errors.New(`ERROR: The last statement must be ended by a semicolon or '-- +migrate StatementEnd' marker.
|
||||
return fmt.Errorf(`ERROR: The last statement must be ended by a semicolon or '-- +migrate StatementEnd' marker.
|
||||
See https://github.com/rubenv/sql-migrate for details.`)
|
||||
}
|
||||
|
||||
return errors.New(fmt.Sprintf(`ERROR: The last statement must be ended by a semicolon, a line whose contents are %q, or '-- +migrate StatementEnd' marker.
|
||||
See https://github.com/rubenv/sql-migrate for details.`, LineSeparator))
|
||||
return fmt.Errorf(`ERROR: The last statement must be ended by a semicolon, a line whose contents are %q, or '-- +migrate StatementEnd' marker.
|
||||
See https://github.com/rubenv/sql-migrate for details.`, LineSeparator)
|
||||
}
|
||||
|
||||
// Checks the line to see if the line has a statement-ending semicolon
|
||||
// or if the line contains a double-dash comment.
|
||||
func endsWithSemicolon(line string) bool {
|
||||
|
||||
prev := ""
|
||||
scanner := bufio.NewScanner(strings.NewReader(line))
|
||||
scanner.Split(bufio.ScanWords)
|
||||
@@ -88,12 +83,12 @@ func parseCommand(line string) (*migrateCommand, error) {
|
||||
cmd := &migrateCommand{}
|
||||
|
||||
if !strings.HasPrefix(line, sqlCmdPrefix) {
|
||||
return nil, errors.New("ERROR: not a sql-migrate command")
|
||||
return nil, fmt.Errorf("ERROR: not a sql-migrate command")
|
||||
}
|
||||
|
||||
fields := strings.Fields(line[len(sqlCmdPrefix):])
|
||||
if len(fields) == 0 {
|
||||
return nil, errors.New(`ERROR: incomplete migration command`)
|
||||
return nil, fmt.Errorf(`ERROR: incomplete migration command`)
|
||||
}
|
||||
|
||||
cmd.Command = fields[0]
|
||||
@@ -151,7 +146,6 @@ func ParseMigration(r io.ReadSeeker) (*ParsedMigration, error) {
|
||||
if cmd.HasOption(optionNoTransaction) {
|
||||
p.DisableTransactionUp = true
|
||||
}
|
||||
break
|
||||
|
||||
case "Down":
|
||||
if len(strings.TrimSpace(buf.String())) > 0 {
|
||||
@@ -161,20 +155,17 @@ func ParseMigration(r io.ReadSeeker) (*ParsedMigration, error) {
|
||||
if cmd.HasOption(optionNoTransaction) {
|
||||
p.DisableTransactionDown = true
|
||||
}
|
||||
break
|
||||
|
||||
case "StatementBegin":
|
||||
if currentDirection != directionNone {
|
||||
ignoreSemicolons = true
|
||||
}
|
||||
break
|
||||
|
||||
case "StatementEnd":
|
||||
if currentDirection != directionNone {
|
||||
statementEnded = (ignoreSemicolons == true)
|
||||
statementEnded = ignoreSemicolons
|
||||
ignoreSemicolons = false
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,11 +207,11 @@ func ParseMigration(r io.ReadSeeker) (*ParsedMigration, error) {
|
||||
|
||||
// diagnose likely migration script errors
|
||||
if ignoreSemicolons {
|
||||
return nil, errors.New("ERROR: saw '-- +migrate StatementBegin' with no matching '-- +migrate StatementEnd'")
|
||||
return nil, fmt.Errorf("ERROR: saw '-- +migrate StatementBegin' with no matching '-- +migrate StatementEnd'")
|
||||
}
|
||||
|
||||
if currentDirection == directionNone {
|
||||
return nil, errors.New(`ERROR: no Up/Down annotations found, so no statements were executed.
|
||||
return nil, fmt.Errorf(`ERROR: no Up/Down annotations found, so no statements were executed.
|
||||
See https://github.com/rubenv/sql-migrate for details.`)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user