Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Add Postgres driver stub

天舟8fa0fe1c721f
diff --git a/plugin/db/driver.go b/plugin/db/driver.go
index 7e837b9ecd..da897adb05 100644
--- a/plugin/db/driver.go
+++ b/plugin/db/driver.go
@@ -16,14 +16,18 @@ import (
type Type string
const (
- Mysql Type = "MYSQL"
+ Mysql Type = "MYSQL"
+ Postgres Type = "POSTGRES"
)
func (e Type) String() string {
switch e {
case Mysql:
return "MYSQL"
+ case Postgres:
+ return "POSTGRES"
}
+
return "UNKNOWN"
}
diff --git a/plugin/db/mysql.go b/plugin/db/mysql.go
index 55a04b0dea..91bb8401d2 100644
--- a/plugin/db/mysql.go
+++ b/plugin/db/mysql.go
@@ -29,7 +29,7 @@ var (
)
func init() {
- register(Mysql, newDriver)
+ register(Mysql, newMySQLDriver)
}
type MySQLDriver struct {
@@ -39,7 +39,7 @@ type MySQLDriver struct {
db *sql.DB
}
-func newDriver(config DriverConfig) Driver {
+func newMySQLDriver(config DriverConfig) Driver {
return &MySQLDriver{
l: config.Logger,
}
diff --git a/plugin/db/pg.go b/plugin/db/pg.go
new file mode 100644
index 0000000000..11cc5ad38c
--- /dev/null
+++ b/plugin/db/pg.go
@@ -0,0 +1,87 @@
+package db
+
+import (
+ "bufio"
+ "context"
+ "database/sql"
+ _ "embed"
+ "fmt"
+ "os"
+
+ _ "github.com/lib/pq"
+ "go.uber.org/zap"
+)
+
+var (
+ _ Driver = (*PostgresDriver)(nil)
+)
+
+func init() {
+ register(Postgres, newPostgresDriver)
+}
+
+type PostgresDriver struct {
+ l *zap.Logger
+ connectionCtx ConnectionContext
+
+ db *sql.DB
+}
+
+func newPostgresDriver(config DriverConfig) Driver {
+ return &PostgresDriver{
+ l: config.Logger,
+ }
+}
+
+func (driver *PostgresDriver) open(config ConnectionConfig, ctx ConnectionContext) (Driver, error) {
+ return nil, fmt.Errorf("not implemented")
+}
+
+func (driver *PostgresDriver) Close(ctx context.Context) error {
+ return driver.db.Close()
+}
+
+func (driver *PostgresDriver) Ping(ctx context.Context) error {
+ return driver.db.PingContext(ctx)
+}
+
+func (driver *PostgresDriver) SyncSchema(ctx context.Context) ([]*DBUser, []*DBSchema, error) {
+ return nil, nil, fmt.Errorf("not implemented")
+}
+
+func (driver *PostgresDriver) Execute(ctx context.Context, statement string) error {
+ tx, err := driver.db.BeginTx(ctx, nil)
+ if err != nil {
+ return err
+ }
+ defer tx.Rollback()
+
+ _, err = tx.ExecContext(ctx, statement)
+ return err
+}
+
+// Migration related
+func (driver *PostgresDriver) NeedsSetupMigration(ctx context.Context) (bool, error) {
+ return false, fmt.Errorf("not implemented")
+}
+
+func (driver *PostgresDriver) SetupMigrationIfNeeded(ctx context.Context) error {
+ return fmt.Errorf("not implemented")
+}
+
+func (driver *PostgresDriver) ExecuteMigration(ctx context.Context, m *MigrationInfo, statement string) error {
+ return fmt.Errorf("not implemented")
+}
+
+func (driver *PostgresDriver) FindMigrationHistoryList(ctx context.Context, find *MigrationHistoryFind) ([]*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 {
+ return fmt.Errorf("not implemented")
+}
+
+func (driver *PostgresDriver) Restore(ctx context.Context, sc *bufio.Scanner) (err error) {
+ return fmt.Errorf("not implemented")
+}