aboutsummaryrefslogtreecommitdiff
path: root/cmd/bun/migrations/20241005143542_1_init.go
blob: dc92797cb17d9f3ee59312f8c3e122bc321de357 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package migrations

import (
	"context"
	"fmt"

	"github.com/uptrace/bun"
	"sh.org.ru/pkg/model"
)

func init() {
	Migrations.MustRegister(func(ctx context.Context, db *bun.DB) error {
		fmt.Print(" [up migration] ")
		if _, err := db.NewCreateTable().Model((*model.Quote)(nil)).Exec(ctx); err != nil {
			return err
		}

		return nil
	}, func(ctx context.Context, db *bun.DB) error {
		fmt.Print(" [down migration] ")
		if _, err := db.NewDropTable().Model((*model.Quote)(nil)).Exec(ctx); err != nil {
			return err
		}

		return nil
	})
}