* feat(host): Add host plugin related schemas and tests This adds the schema files for host plugins, plugin based catalogs and plugin based sets. This also adds the protos and tests which utilize gorm to ensure the schemas enforce the constraints we expect. Along with this change was a migration which moved catalog names to the base type table so we can ensure all catalogs in a single scope, regardless of subtype, have a unique name. * Updated plugin schemas to do the following: - Add plugin_executable table - plugin table now also has scope_id and name w/ uniqueness constraints - host_plugin no longer has id_prefix column - host_plugin separates name and plugin_name - plugin_version table renamed version to symantic_version column. * Fix typo in delete_plugin_subtype trigger. Add update test for host plugins. * Update id prefixes. Fix public_id typos in protos and plugin_executable name in sql diagrams. * Created internal/plugin and moved base plugin structs to it and moved host plugin subdirectory to it. * Created internal/plugin and moved base plugin structs to it and moved host plugin subdirectory to it. * Add first pass at enums for OS and Arch supported by plugin executables. * Capitalizing the const enums for OS and Architectures. * Add comments to sql files. * Reviewer comments. Remove unsupported OSes and Archs from SQL and go constants. Add missing tests. * Be more permissive in the values the db accepts. The go logic can restrict which values it will allow getting populated into the db. * Removing constraints on which values can be placed inside operating_system and architecture columns. * Updating test helper functions to only create a single catalog or set. * Move files to new migration version. * Fixing job/plugin test. * Update table names, named a number of constraints, remove plugin version and executable tables. * Add constraints for plugin name and id prefix. * Rename constraint, remove unhelpful comment block. * Adding semantic version to plugin_host and set attributes to not null. * Remove semantic versioning from all locations. * Remove semantic_version from plugin_host table comment. * Fix op copy/paste error. Don't use deprecated errors methods. Update constraint names. Add docs. * Apply suggestions from code review Fixing constraint names. Co-authored-by: Michael Gaffney <mgaffney@users.noreply.github.com>
db package
Usage
Just some high-level usage highlights to get you started. Read the godocs for a complete list of capabilities and their documentation.
conn, _ := gorm.Open("postgres", url)
// Db implements both the Reader and Writer interfaces
rw := Db{Tx: conn}
// There are writer methods like: Create, Update and Delete
// that will write Gorm struct to the db. These writer methods
// all support options for writing Oplog entries for the
// caller: WithOplog(yourWrapper, yourMetadata)
// the caller is responsible for the transaction life cycle of the writer
// and if an error is returned the caller must decide what to do with
// the transaction, which is almost always a rollback for the caller.
err = rw.Create(context.Background(), user)
// There are reader methods like: LookupByPublicId,
// LookupByName, SearchBy, LookupBy, etc
// which will lookup resources for you and scan them into your Gorm struct
err = rw.LookupByPublicId(context.Background(), foundUser)
// There's reader ScanRows that facilitates scanning rows from
// a query into your Gorm struct
where := "select * from test_users where name in ($1, $2)"
rows, err := rw.Query(context.Background(), where, []interface{}{"alice", "bob"})
defer rows.Close()
for rows.Next() {
user := db_test.NewTestUser()
// scan the row into your Gorm struct
if err := rw.ScanRows(rows, &user); err != nil {
return err
}
// Do something with the Gorm user struct
}
// DoTx is a writer function that wraps a TxHandler
// in a retryable transaction. You simply implement a
// TxHandler that does your writes and hand the handler
// to DoTx, which will wrap the writes in a retryable
// transaction with the retry attempts and backoff
// strategy you specify via options.
_, err = w.DoTx(
context.Background(),
10, // ten retries
ExpBackoff{}, // exponential backoff
func(w Writer) error {
// the TxHandler updates the user's friendly name
return w.Update(context.Background(), user, []string{"FriendlyName"},
// write oplogs for this update
WithOplog(
InitTestWrapper(t),
oplog.Metadata{
"key-only": nil,
"deployment": []string{"amex"},
"project": []string{"central-info-systems", "local-info-systems"},
},
),
)
})