-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: add evm-scoped db type to ensure that services are not violating…
… db boundaries. hint: they are and it's painful
- Loading branch information
1 parent
832e137
commit a86f233
Showing
77 changed files
with
600 additions
and
459 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package db | ||
|
||
import ( | ||
"net/url" | ||
|
||
"github.com/google/uuid" | ||
"github.com/smartcontractkit/sqlx" | ||
|
||
"github.com/smartcontractkit/chainlink/v2/core/config" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/pg" | ||
) | ||
|
||
type ScopedDB struct { | ||
*sqlx.DB | ||
} | ||
|
||
var schema = "evm" | ||
|
||
func NewScopedDB(uuid uuid.UUID, cfg config.Database) (*ScopedDB, error) { | ||
db, err := pg.OpenUnlockedDB(uuid, cfg, pg.WithSchema(schema)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &ScopedDB{DB: db}, nil | ||
} | ||
|
||
func (s *ScopedDB) SqlxDB() *sqlx.DB { | ||
return s.DB | ||
} | ||
|
||
func ScopedConnection(dbURL url.URL) (evmScopedConnection url.URL) { | ||
return pg.SchemaScopedConnection(dbURL, schema) | ||
} | ||
|
||
func UseEVMSchema() pg.ConnectionOpt { | ||
return func(u *url.URL) error { | ||
return pg.WithSchema(schema)(u) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.