go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/projects/kana-server/pkg/model/migrations.go (about)

     1  /*
     2  
     3  Copyright (c) 2023 - Present. Will Charczuk. All rights reserved.
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository.
     5  
     6  */
     7  
     8  package model
     9  
    10  import (
    11  	"go.charczuk.com/sdk/apputil"
    12  	"go.charczuk.com/sdk/db/dbgen"
    13  	"go.charczuk.com/sdk/db/migration"
    14  
    15  	"go.charczuk.com/projects/kana-server/pkg/types"
    16  )
    17  
    18  // Migrations returns the migration suite to bootstrap the database.
    19  func Migrations(opts ...migration.SuiteOption) *migration.Suite {
    20  	return migration.New(
    21  		append(opts,
    22  			migration.OptGroups(
    23  				append(apputil.MigrationGroups(),
    24  					quizzes(),
    25  					quizResults(),
    26  				)...,
    27  			),
    28  		)...,
    29  	)
    30  }
    31  
    32  //
    33  // specific table definitions
    34  //
    35  
    36  func quizzes() *migration.Group {
    37  	return migration.NewGroupWithAction(
    38  		dbgen.TableFrom(types.Quiz{},
    39  			dbgen.ForeignKey(types.Quiz{}, "user_id", apputil.User{}, "id"),
    40  		),
    41  	)
    42  }
    43  
    44  func quizResults() *migration.Group {
    45  	return migration.NewGroupWithAction(
    46  		dbgen.TableFrom(types.QuizResult{},
    47  			dbgen.ForeignKey(types.QuizResult{}, "user_id", apputil.User{}, "id"),
    48  			dbgen.ForeignKey(types.QuizResult{}, "quiz_id", types.Quiz{}, "id"),
    49  		),
    50  	)
    51  }