Documentation
¶
Index ¶
- Variables
- type Manifest
- type Migration
- type Migrator
- func (s *Migrator) CreateMigrationSchema() error
- func (s *Migrator) ExecuteExtensionDataPopulation() error
- func (s *Migrator) ExecuteMigrations(manifest Manifest) error
- func (s *Migrator) ExecuteStepwiseMigrations() error
- func (s *Migrator) GenerateManifest() (Manifest, error)
- func (s *Migrator) GenerateManifestAfterVersion(lastVersion version.Version) (Manifest, error)
- func (s *Migrator) HasMigrationTable() (bool, error)
- func (s *Migrator) LatestMigration() (model.Migration, error)
- func (s *Migrator) RequiresMigration() (bool, error)
- type Source
Constants ¶
This section is empty.
Variables ¶
var ExtensionMigrations embed.FS
var FossMigrations embed.FS
Functions ¶
This section is empty.
Types ¶
type Manifest ¶
Manifest is a collection of available migrations. VersionTable is used to order and store all version of migrations contained in the manifest. Migrations is the actual underlying map of [version:[]migration]
func NewManifest ¶
func NewManifest() Manifest
NewManifest creates a new Manifest and initializes the migrations map
func (*Manifest) AddMigration ¶
AddMigration will add migrations to the correct location in the migrations map, with care to make sure the map is initialized, as well as the version location within the map.
type Migration ¶
Migration contains information about a specific migration such as the file location, it's Source, and Version.
type Migrator ¶
Migrator is the main SQL migration tool for BloodHound.
func NewMigrator ¶
NewMigrator returns a new Migrator with the FossMigrations Source predefined.
func (*Migrator) CreateMigrationSchema ¶
CreateMigrationSchema creates all the necessary SQL schema for tracking migration status.
func (*Migrator) ExecuteExtensionDataPopulation ¶
func (*Migrator) ExecuteMigrations ¶
ExecuteMigrations takes a Manifest and runs all migrations contained in it, by version. It starts by ranging over the Manifest.VersionTable, which is an ordered list of all versions covered in the Manifest. Each version entry in the Manifest map may have multiple migrations from different sources. To ensure consistency, all migrations for each version are run in a transaction, as well as logging the successful migration entry in the `migrations` table.
func (*Migrator) ExecuteStepwiseMigrations ¶
ExecuteStepwiseMigrations will run all necessary migrations for a deployment. It begins by checking if migration schema exists. If it does not, we assume the deployment is a new installation, otherwise we assume it may have migration updates.
If the deployment is new, we install migration schema to track migrations and then build a manifest of all existing migrations
If the deployment already existed, we query for the last successful migration run and then build a manifest starting after the last successful version
Once schema is verified and a manifest is created, we run ExecuteMigrations.
func (*Migrator) GenerateManifest ¶
GenerateManifest is a wrapper around GenerateManifestAfterVersion, using -1.-1.-1 as the version. This ensures that a full manifest of all available migrations is generated. This is most useful for new installations.
func (*Migrator) GenerateManifestAfterVersion ¶
GenerateManifestAfterVersion takes a version.Version argument and uses that to generate a manifest from the available migration Source's. It will loop through sources and build Migration's from the available migration files. Files labeled `schema` are considered the initial migration and get versioned as v0.0.0. All valid migrations that are versioned after the version given will be added to the manifest for migration. The final step is the build and sort the VersionTable that will be used for applying the migration in order by ExecuteMigrations.
func (*Migrator) HasMigrationTable ¶
HasMigrationTable is a utility for checking if migration schema is initialized. We assume that if the `migrations` table exists, the schema must be initialized, and vice versa.
func (*Migrator) LatestMigration ¶
LatestMigration retrieves the last entry in the migration table to determine what the last successful migration version was.