@@ -548,8 +548,49 @@ func (a *API) Serve(ctx context.Context) error {
548
548
return sdk .WrapError (err , "cannot connect to cache store" )
549
549
}
550
550
551
- log .Info (ctx , "Initializing HTTP router" )
552
551
a .GoRoutines = sdk .NewGoRoutines (ctx )
552
+
553
+ log .Info (ctx , "Running migration" )
554
+ migrate .Add (ctx , sdk.Migration {Name : "RunsSecrets" , Release : "0.47.0" , Blocker : false , Automatic : true , ExecFunc : func (ctx context.Context ) error {
555
+ return migrate .RunsSecrets (ctx , a .DBConnectionFactory .GetDBMap (gorpmapping .Mapper ))
556
+ }})
557
+
558
+ migrate .Add (ctx , sdk.Migration {Name : "AuthConsumerTokenExpiration" , Release : "0.47.0" , Blocker : true , Automatic : true , ExecFunc : func (ctx context.Context ) error {
559
+ return migrate .AuthConsumerTokenExpiration (ctx , a .DBConnectionFactory .GetDBMap (gorpmapping .Mapper ), time .Duration (a .Config .Auth .TokenDefaultDuration )* (24 * time .Hour ))
560
+ }})
561
+
562
+ migrate .Add (ctx , sdk.Migration {Name : "ArtifactoryIntegration" , Release : "0.49.0" , Blocker : true , Automatic : true , ExecFunc : func (ctx context.Context ) error {
563
+ return migrate .ArtifactoryIntegration (ctx , a .DBConnectionFactory .GetDBMap (gorpmapping .Mapper ))
564
+ }})
565
+
566
+ isFreshInstall , errF := version .IsFreshInstall (a .mustDB ())
567
+ if errF != nil {
568
+ return sdk .WrapError (errF , "Unable to check if it's a fresh installation of CDS" )
569
+ }
570
+
571
+ if isFreshInstall {
572
+ if err := migrate .SaveAllMigrations (a .mustDB ()); err != nil {
573
+ return sdk .WrapError (err , "Cannot save all migrations to done" )
574
+ }
575
+ } else {
576
+ if sdk .VersionCurrent ().Version != "" && ! strings .HasPrefix (sdk .VersionCurrent ().Version , "snapshot" ) {
577
+ major , minor , _ , errV := version .MaxVersion (a .mustDB ())
578
+ if errV != nil {
579
+ return sdk .WrapError (errV , "Cannot fetch max version of CDS already started" )
580
+ }
581
+ if major != 0 || minor != 0 {
582
+ minSemverCompatible , _ := semver .Parse (migrate .MinCompatibleRelease )
583
+ if major < minSemverCompatible .Major || (major == minSemverCompatible .Major && minor < minSemverCompatible .Minor ) {
584
+ return fmt .Errorf ("there are some mandatory migrations which aren't done. Please check each changelog of CDS. Maybe you have skipped a release migration. The minimum compatible release is %s, please update to this release before" , migrate .MinCompatibleRelease )
585
+ }
586
+ }
587
+ }
588
+
589
+ // Run all migrations in several goroutines
590
+ migrate .Run (ctx , a .mustDB ())
591
+ }
592
+
593
+ log .Info (ctx , "Initializing HTTP router" )
553
594
a .Router = & Router {
554
595
Mux : mux .NewRouter (),
555
596
Background : ctx ,
@@ -710,41 +751,6 @@ func (a *API) Serve(ctx context.Context) error {
710
751
a .WorkflowRunCraft (ctx , 100 * time .Millisecond )
711
752
})
712
753
713
- migrate .Add (ctx , sdk.Migration {Name : "RunsSecrets" , Release : "0.47.0" , Blocker : false , Automatic : true , ExecFunc : func (ctx context.Context ) error {
714
- return migrate .RunsSecrets (ctx , a .DBConnectionFactory .GetDBMap (gorpmapping .Mapper ))
715
- }})
716
-
717
- migrate .Add (ctx , sdk.Migration {Name : "AuthConsumerTokenExpiration" , Release : "0.47.0" , Blocker : true , Automatic : true , ExecFunc : func (ctx context.Context ) error {
718
- return migrate .AuthConsumerTokenExpiration (ctx , a .DBConnectionFactory .GetDBMap (gorpmapping .Mapper ), time .Duration (a .Config .Auth .TokenDefaultDuration )* (24 * time .Hour ))
719
- }})
720
-
721
- isFreshInstall , errF := version .IsFreshInstall (a .mustDB ())
722
- if errF != nil {
723
- return sdk .WrapError (errF , "Unable to check if it's a fresh installation of CDS" )
724
- }
725
-
726
- if isFreshInstall {
727
- if err := migrate .SaveAllMigrations (a .mustDB ()); err != nil {
728
- return sdk .WrapError (err , "Cannot save all migrations to done" )
729
- }
730
- } else {
731
- if sdk .VersionCurrent ().Version != "" && ! strings .HasPrefix (sdk .VersionCurrent ().Version , "snapshot" ) {
732
- major , minor , _ , errV := version .MaxVersion (a .mustDB ())
733
- if errV != nil {
734
- return sdk .WrapError (errV , "Cannot fetch max version of CDS already started" )
735
- }
736
- if major != 0 || minor != 0 {
737
- minSemverCompatible , _ := semver .Parse (migrate .MinCompatibleRelease )
738
- if major < minSemverCompatible .Major || (major == minSemverCompatible .Major && minor < minSemverCompatible .Minor ) {
739
- return fmt .Errorf ("there are some mandatory migrations which aren't done. Please check each changelog of CDS. Maybe you have skipped a release migration. The minimum compatible release is %s, please update to this release before" , migrate .MinCompatibleRelease )
740
- }
741
- }
742
- }
743
-
744
- // Run all migrations in several goroutines
745
- migrate .Run (ctx , a .mustDB ())
746
- }
747
-
748
754
log .Info (ctx , "Bootstrapping database..." )
749
755
defaultValues := sdk.DefaultValues {
750
756
DefaultGroupName : a .Config .Auth .DefaultGroup ,
0 commit comments