update_dashboards_savedviews.go
015_update_dashboards_savedviews.go - Overview
- Overview
This file defines a SQL migration to update the dashboards
and saved_views
tables by adding an org_id
column as a foreign key referencing the organizations
table. It also populates this column with the existing organization ID if only one exists.
- Detailed Documentation
type updateDashboardAndSavedViews struct
- Purpose: Represents the migration to update the dashboards and saved views tables.
- Fields:
store
: An instance ofsqlstore.SQLStore
used for database interactions.
func NewUpdateDashboardAndSavedViewsFactory(sqlstore sqlstore.SQLStore) factory.ProviderFactory[SQLMigration, Config]
- Purpose: Creates a new factory for the
updateDashboardAndSavedViews
migration. - Parameters:
sqlstore
: Thesqlstore.SQLStore
instance to be used by the migration.
- Returns: A
factory.ProviderFactory
that createsSQLMigration
instances.
func newUpdateDashboardAndSavedViews(_ context.Context, _ factory.ProviderSettings, _ Config, store sqlstore.SQLStore) (SQLMigration, error)
- Purpose: Creates a new instance of the
updateDashboardAndSavedViews
migration. - Parameters:
_
: Acontext.Context
(not used)._
:factory.ProviderSettings
(not used)._
:Config
(not used).store
: Thesqlstore.SQLStore
instance to be used by the migration.
- Returns: A new
SQLMigration
instance and an error, if any.
func (migration *updateDashboardAndSavedViews) Register(migrations *migrate.Migrations) error
- Purpose: Registers the
Up
andDown
functions of the migration with the providedmigrate.Migrations
instance. - Parameters:
migrations
: Themigrate.Migrations
instance to register the migration with.
- Returns: An error, if any.
func (migration *updateDashboardAndSavedViews) Up(ctx context.Context, db *bun.DB) error
- Purpose: Implements the "Up" migration logic, adding the
org_id
column to thedashboards
andsaved_views
tables and populating it with the existing organization ID if only one exists. - Parameters:
ctx
: The context for the operation.db
: Thebun.DB
instance to use for database operations.
- Returns: An error, if any.
func (migration *updateDashboardAndSavedViews) Down(ctx context.Context, db *bun.DB) error
- Purpose: Implements the "Down" migration logic (reverting the "Up" migration). Currently, it does nothing and returns
nil
. - Parameters:
ctx
: The context for the operation.db
: Thebun.DB
instance to use for database operations.
- Returns:
nil
.
- Code Examples
No examples are needed.
- Clarity and Accuracy
The documentation reflects the code accurately.
- Markdown & MDX Perfection
The markdown is correctly formatted.
- Edge Cases To Avoid Breaking MDX:
All potential MDX issues have been avoided.
- Getting Started Relevance
Include in Getting Started: NO