migrations

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

README

Migrations are in SQL files of the format TIMESTAMP_NAME.up.sql and TIMESTAMP_NAME.down.sql. Names do not necessarily need to be unique, but timestamps do. The .up.sql is done for schema upgrades, and .down.sql for when rolling back a schema upgrade. If it is unsafe to roll back, create a .down.sql file containing text to describe the reason that is not valid SQL.

Once a migration has been used on a real site, it should in general NEVER be changed so that we can maintain a consistent environment. If an exception needs to be made include a comment "-- Allow hash changing" to ignore this. All sites where it was deployed will require manual schema editing to be consistent with the new schema unless the change was to add an UPDATE or DELETE command to modify the data instead of the schema.

While developing, if you want to replace a version of a migration that was only present in a prior version of your workspace, manually undo the changes made to the schema, then either run the SQL "delete from migrations where id = 'TIMESTAMP'" or start using a new timestamp.

When a new version of powershelf_manager is run, all .up.sql migrations that were not present before are run in a single transaction in the order of their timestamps.

Documentation

Overview

* SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MigrateWithDB

func MigrateWithDB(ctx context.Context, db *bun.DB) error

MigrateWithDB ensures that the database contains all currently known migrations. Accepts a *bun.DB directly.

func RollbackWithDB

func RollbackWithDB(ctx context.Context, db *bun.DB, rollbackTime time.Time) error

RollbackWithDB will roll back migrations that have been applied since the given time. Accepts a *bun.DB directly.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL