go.temporal.io/server@v1.23.0/common/persistence/sql/sqlplugin/interfaces.go (about) 1 // The MIT License 2 // 3 // Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. 4 // 5 // Copyright (c) 2020 Uber Technologies, Inc. 6 // 7 // Permission is hereby granted, free of charge, to any person obtaining a copy 8 // of this software and associated documentation files (the "Software"), to deal 9 // in the Software without restriction, including without limitation the rights 10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 // copies of the Software, and to permit persons to whom the Software is 12 // furnished to do so, subject to the following conditions: 13 // 14 // The above copyright notice and this permission notice shall be included in 15 // all copies or substantial portions of the Software. 16 // 17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 // THE SOFTWARE. 24 25 package sqlplugin 26 27 import ( 28 "context" 29 "database/sql" 30 31 "github.com/jmoiron/sqlx" 32 "go.temporal.io/server/common/config" 33 "go.temporal.io/server/common/resolver" 34 ) 35 36 type ( 37 DbKind int 38 ) 39 40 const ( 41 DbKindUnknown DbKind = iota 42 DbKindMain 43 DbKindVisibility 44 ) 45 46 type ( 47 // Plugin defines the interface for any SQL database that needs to implement 48 Plugin interface { 49 CreateDB(dbKind DbKind, cfg *config.SQL, r resolver.ServiceResolver) (DB, error) 50 CreateAdminDB(dbKind DbKind, cfg *config.SQL, r resolver.ServiceResolver) (AdminDB, error) 51 } 52 53 // TableCRUD defines the API for interacting with the database tables 54 TableCRUD interface { 55 ClusterMetadata 56 Namespace 57 Visibility 58 QueueMessage 59 QueueMetadata 60 QueueV2Message 61 QueueV2Metadata 62 63 MatchingTask 64 MatchingTaskQueue 65 66 HistoryNode 67 HistoryTree 68 69 HistoryShard 70 71 HistoryExecution 72 HistoryExecutionBuffer 73 HistoryExecutionActivity 74 HistoryExecutionChildWorkflow 75 HistoryExecutionTimer 76 HistoryExecutionRequestCancel 77 HistoryExecutionSignal 78 HistoryExecutionSignalRequest 79 80 HistoryImmediateTask 81 HistoryScheduledTask 82 HistoryTransferTask 83 HistoryTimerTask 84 HistoryReplicationTask 85 HistoryReplicationDLQTask 86 HistoryVisibilityTask 87 } 88 89 // AdminCRUD defines admin operations for CLI and test suites 90 AdminCRUD interface { 91 CreateSchemaVersionTables() error 92 ReadSchemaVersion(database string) (string, error) 93 UpdateSchemaVersion(database string, newVersion string, minCompatibleVersion string) error 94 WriteSchemaUpdateLog(oldVersion string, newVersion string, manifestMD5 string, desc string) error 95 ListTables(database string) ([]string, error) 96 DropTable(table string) error 97 DropAllTables(database string) error 98 CreateDatabase(database string) error 99 DropDatabase(database string) error 100 Exec(stmt string, args ...interface{}) error 101 } 102 103 // Tx defines the API for a SQL transaction 104 Tx interface { 105 TableCRUD 106 Commit() error 107 Rollback() error 108 } 109 110 // DB defines the API for regular SQL operations of a Temporal server 111 DB interface { 112 TableCRUD 113 114 BeginTx(ctx context.Context) (Tx, error) 115 PluginName() string 116 DbName() string 117 IsDupEntryError(err error) bool 118 Close() error 119 } 120 121 // AdminDB defines the API for admin SQL operations for CLI and testing suites 122 AdminDB interface { 123 AdminCRUD 124 PluginName() string 125 ExpectedVersion() string 126 VerifyVersion() error 127 Close() error 128 } 129 130 // Conn defines the API for a single database connection 131 Conn interface { 132 Rebind(query string) string 133 ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) 134 NamedExecContext(ctx context.Context, query string, arg interface{}) (sql.Result, error) 135 GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error 136 SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error 137 PrepareNamedContext(ctx context.Context, query string) (*sqlx.NamedStmt, error) 138 } 139 )