Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Rename MySQLDriver/PostgresDriver to Driver since we no longer have name collision
天舟75040560ada0
diff --git a/plugin/db/mysql/mysql.go b/plugin/db/mysql/mysql.goindex 68bf1b7d59..eb4751c90f 100644--- a/plugin/db/mysql/mysql.go+++ b/plugin/db/mysql/mysql.go@@ -26,27 +26,27 @@ var ("sys": true,}- _ db.Driver = (*MySQLDriver)(nil)+ _ db.Driver = (*Driver)(nil))func init() {- db.Register(db.MySQL, newMySQLDriver)+ db.Register(db.MySQL, newDriver)}-type MySQLDriver struct {+type Driver struct {l *zap.LoggerconnectionCtx db.ConnectionContextdb *sql.DB}-func newMySQLDriver(config db.DriverConfig) db.Driver {- return &MySQLDriver{+func newDriver(config db.DriverConfig) db.Driver {+ return &Driver{l: config.Logger,}}-func (driver *MySQLDriver) Open(config db.ConnectionConfig, ctx db.ConnectionContext) (db.Driver, error) {+func (driver *Driver) Open(config db.ConnectionConfig, ctx db.ConnectionContext) (db.Driver, error) {protocol := "tcp"if strings.HasPrefix(config.Host, "/") {protocol = "unix"@@ -90,15 +90,15 @@ func (driver *MySQLDriver) Open(config db.ConnectionConfig, ctx db.ConnectionConreturn driver, nil}-func (driver *MySQLDriver) Close(ctx context.Context) error {+func (driver *Driver) Close(ctx context.Context) error {return driver.db.Close()}-func (driver *MySQLDriver) Ping(ctx context.Context) error {+func (driver *Driver) Ping(ctx context.Context) error {return driver.db.PingContext(ctx)}-func (driver *MySQLDriver) SyncSchema(ctx context.Context) ([]*db.DBUser, []*db.DBSchema, error) {+func (driver *Driver) SyncSchema(ctx context.Context) ([]*db.DBUser, []*db.DBSchema, error) {// Query MySQL versionquery := "SELECT VERSION()"versionRow, err := driver.db.QueryContext(ctx, query)@@ -412,7 +412,7 @@ func (driver *MySQLDriver) SyncSchema(ctx context.Context) ([]*db.DBUser, []*db.return userList, schemaList, err}-func (driver *MySQLDriver) Execute(ctx context.Context, statement string) error {+func (driver *Driver) Execute(ctx context.Context, statement string) error {tx, err := driver.db.BeginTx(ctx, nil)if err != nil {return err@@ -424,7 +424,7 @@ func (driver *MySQLDriver) Execute(ctx context.Context, statement string) error}// Migration related-func (driver *MySQLDriver) NeedsSetupMigration(ctx context.Context) (bool, error) {+func (driver *Driver) NeedsSetupMigration(ctx context.Context) (bool, error) {const query = `SELECT1@@ -444,7 +444,7 @@ func (driver *MySQLDriver) NeedsSetupMigration(ctx context.Context) (bool, errorreturn true, nil}-func (driver *MySQLDriver) SetupMigrationIfNeeded(ctx context.Context) error {+func (driver *Driver) SetupMigrationIfNeeded(ctx context.Context) error {setup, err := driver.NeedsSetupMigration(ctx)if err != nil {return nil@@ -472,7 +472,7 @@ func (driver *MySQLDriver) SetupMigrationIfNeeded(ctx context.Context) error {return nil}-func (driver *MySQLDriver) ExecuteMigration(ctx context.Context, m *db.MigrationInfo, statement string) error {+func (driver *Driver) ExecuteMigration(ctx context.Context, m *db.MigrationInfo, statement string) error {tx, err := driver.db.BeginTx(ctx, nil)if err != nil {return err@@ -576,7 +576,7 @@ func (driver *MySQLDriver) ExecuteMigration(ctx context.Context, m *db.Migrationreturn nil}-func (driver *MySQLDriver) FindMigrationHistoryList(ctx context.Context, find *db.MigrationHistoryFind) ([]*db.MigrationHistory, error) {+func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.MigrationHistoryFind) ([]*db.MigrationHistory, error) {tx, err := driver.db.BeginTx(ctx, nil)if err != nil {return nil, err@@ -823,7 +823,7 @@ const ("DELIMITER ;\n")-func (driver *MySQLDriver) Dump(ctx context.Context, database string, out *os.File, schemaOnly bool) error {+func (driver *Driver) Dump(ctx context.Context, database string, out *os.File, schemaOnly bool) error {// mysqldump -u root --databases dbName --no-data --routines --events --triggers --compacttxn, err := driver.db.BeginTx(ctx, &sql.TxOptions{ReadOnly: true})@@ -941,7 +941,7 @@ func (driver *MySQLDriver) Dump(ctx context.Context, database string, out *os.Fireturn nil}-func (driver *MySQLDriver) Restore(ctx context.Context, sc *bufio.Scanner) (err error) {+func (driver *Driver) Restore(ctx context.Context, sc *bufio.Scanner) (err error) {txn, err := driver.db.BeginTx(ctx, nil)if err != nil {return errdiff --git a/plugin/db/pg/pg.go b/plugin/db/pg/pg.goindex 926ec2514a..7c0cd06edf 100644--- a/plugin/db/pg/pg.go+++ b/plugin/db/pg/pg.go@@ -14,43 +14,43 @@ import ()var (- _ db.Driver = (*PostgresDriver)(nil)+ _ db.Driver = (*Driver)(nil))func init() {- db.Register(db.Postgres, newPostgresDriver)+ db.Register(db.Postgres, newDriver)}-type PostgresDriver struct {+type Driver struct {l *zap.LoggerconnectionCtx db.ConnectionContextdb *sql.DB}-func newPostgresDriver(config db.DriverConfig) db.Driver {- return &PostgresDriver{+func newDriver(config db.DriverConfig) db.Driver {+ return &Driver{l: config.Logger,}}-func (driver *PostgresDriver) Open(config db.ConnectionConfig, ctx db.ConnectionContext) (db.Driver, error) {+func (driver *Driver) Open(config db.ConnectionConfig, ctx db.ConnectionContext) (db.Driver, error) {return nil, fmt.Errorf("not implemented")}-func (driver *PostgresDriver) Close(ctx context.Context) error {+func (driver *Driver) Close(ctx context.Context) error {return driver.db.Close()}-func (driver *PostgresDriver) Ping(ctx context.Context) error {+func (driver *Driver) Ping(ctx context.Context) error {return driver.db.PingContext(ctx)}-func (driver *PostgresDriver) SyncSchema(ctx context.Context) ([]*db.DBUser, []*db.DBSchema, error) {+func (driver *Driver) SyncSchema(ctx context.Context) ([]*db.DBUser, []*db.DBSchema, error) {return nil, nil, fmt.Errorf("not implemented")}-func (driver *PostgresDriver) Execute(ctx context.Context, statement string) error {+func (driver *Driver) Execute(ctx context.Context, statement string) error {tx, err := driver.db.BeginTx(ctx, nil)if err != nil {return err@@ -62,27 +62,27 @@ func (driver *PostgresDriver) Execute(ctx context.Context, statement string) err}// Migration related-func (driver *PostgresDriver) NeedsSetupMigration(ctx context.Context) (bool, error) {+func (driver *Driver) NeedsSetupMigration(ctx context.Context) (bool, error) {return false, fmt.Errorf("not implemented")}-func (driver *PostgresDriver) SetupMigrationIfNeeded(ctx context.Context) error {+func (driver *Driver) SetupMigrationIfNeeded(ctx context.Context) error {return fmt.Errorf("not implemented")}-func (driver *PostgresDriver) ExecuteMigration(ctx context.Context, m *db.MigrationInfo, statement string) error {+func (driver *Driver) ExecuteMigration(ctx context.Context, m *db.MigrationInfo, statement string) error {return fmt.Errorf("not implemented")}-func (driver *PostgresDriver) FindMigrationHistoryList(ctx context.Context, find *db.MigrationHistoryFind) ([]*db.MigrationHistory, error) {+func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.MigrationHistoryFind) ([]*db.MigrationHistory, error) {return nil, fmt.Errorf("not implemented")}// Dump and restore-func (driver *PostgresDriver) Dump(ctx context.Context, database string, out *os.File, schemaOnly bool) error {+func (driver *Driver) Dump(ctx context.Context, database string, out *os.File, schemaOnly bool) error {return fmt.Errorf("not implemented")}-func (driver *PostgresDriver) Restore(ctx context.Context, sc *bufio.Scanner) (err error) {+func (driver *Driver) Restore(ctx context.Context, sc *bufio.Scanner) (err error) {return fmt.Errorf("not implemented")}