Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extra/Lamdera/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ check =
flags Lamdera.CLI.Check.Flags
|-- onOff "destructive-migration" "Generate a migration that will drop all production data when deployed, instead of the usual automatic migration generation."
|-- onOff "force" "Force a production check for Evergreen, even if we're on a non main/master branch (i.e. a preview). You shouldn't be using this unless you know what you're doing."
|-- onOff "only-preserve-backend" "Generate migrations that only preserve the BackendModel; all other types use ModelUnchanged/MsgUnchanged."
in
Terminal.Command "check" (Common summary) details example noArgs checkFlags Lamdera.CLI.Check.run

Expand Down
9 changes: 5 additions & 4 deletions extra/Lamdera/CLI/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,16 @@ data Flags =
Flags
{ _destructiveMigration :: Bool
, _force :: Bool
, _onlyPreserveBackend :: Bool
}


run_ :: IO ()
run_ = run () (Lamdera.CLI.Check.Flags { _destructiveMigration = False, _force = False })
run_ = run () (Lamdera.CLI.Check.Flags { _destructiveMigration = False, _force = False, _onlyPreserveBackend = False })


run :: () -> Lamdera.CLI.Check.Flags -> IO ()
run () flags@(Lamdera.CLI.Check.Flags destructiveMigration force) = do
run () flags@(Lamdera.CLI.Check.Flags destructiveMigration force onlyPreserveBackend) = do
debug_ "Starting check..."

inProduction_ <- Lamdera.inProduction
Expand All @@ -93,7 +94,7 @@ run () flags@(Lamdera.CLI.Check.Flags destructiveMigration force) = do


runHelp :: () -> Lamdera.CLI.Check.Flags -> IO ()
runHelp () flags@(Lamdera.CLI.Check.Flags destructiveMigration force) = do
runHelp () flags@(Lamdera.CLI.Check.Flags destructiveMigration force onlyPreserveBackend) = do
Lamdera.setCheckMode True

-- appNameEnvM <- Env.lookupEnv "LAMDERA_APP_NAME"
Expand Down Expand Up @@ -320,7 +321,7 @@ onlineCheck root appName inDebug localTypes externalTypeWarnings isHoistRebuild
then
Lamdera.Evergreen.MigrationDestructive.generate lastLocalTypeChangeVersion nextVersion typeCompares
else
Lamdera.Evergreen.MigrationGenerator.betweenVersions typeCompares lastLocalTypeChangeVersion nextVersion root
Lamdera.Evergreen.MigrationGenerator.betweenVersions onlyPreserveBackend typeCompares lastLocalTypeChangeVersion nextVersion root
writeUtf8 nextMigrationPath defaultMigrations

Progress.throw $
Expand Down
15 changes: 9 additions & 6 deletions extra/Lamdera/Evergreen/MigrationGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import qualified Lamdera.Wire3.Helpers
import Lamdera.Evergreen.MigrationGeneratorHelpers
import Lamdera.Evergreen.MigrationSpecialCases

betweenVersions :: CoreTypeDiffs -> Int -> Int -> String -> IO Text
betweenVersions coreTypeDiffs oldVersion newVersion root = do
betweenVersions :: Bool -> CoreTypeDiffs -> Int -> Int -> String -> IO Text
betweenVersions onlyPreserveBackend coreTypeDiffs oldVersion newVersion root = do
let
paths = NE.List ("src/Evergreen/V" <> show oldVersion <> "/Types.elm") ["src/Evergreen/V" <> show newVersion <> "/Types.elm"]
moduleNameString = "Evergreen.V" <> show newVersion <> ".Types"
Expand All @@ -46,26 +46,29 @@ betweenVersions coreTypeDiffs oldVersion newVersion root = do
case Map.lookup (N.fromChars moduleNameString) interfaces of
Just interface -> do
debug $ "starting generatefor"
generateFor coreTypeDiffs oldVersion newVersion interfaces (interfaces Sanity.! (N.fromChars $ "Evergreen.V" <> show newVersion <> ".Types"))
generateFor onlyPreserveBackend coreTypeDiffs oldVersion newVersion interfaces (interfaces Sanity.! (N.fromChars $ "Evergreen.V" <> show newVersion <> ".Types"))

Nothing ->
error $ "Fatal: could not find the module `" <> moduleNameString <> "`, please report this issue in Discord with your project code."

pure $ Ext.ElmFormat.formatOrPassthrough res

generateFor :: CoreTypeDiffs -> Int -> Int -> Interfaces -> Interface.Interface -> IO Text
generateFor coreTypeDiffs oldVersion newVersion interfaces iface_Types = do
generateFor :: Bool -> CoreTypeDiffs -> Int -> Int -> Interfaces -> Interface.Interface -> IO Text
generateFor onlyPreserveBackend coreTypeDiffs oldVersion newVersion interfaces iface_Types = do
let
moduleName :: ModuleName.Canonical
moduleName = ModuleName.Canonical (Pkg.Name "author" "project") (N.fromChars $ "Evergreen.V" <> show newVersion <> ".Types")

migrationModuleText = T.concat ["Evergreen.Migrate.V", show_ newVersion]

typeDidChange t oldHash newHash =
oldHash /= newHash && not (onlyPreserveBackend && t /= N.fromChars "BackendModel")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably also want BackendMsg here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is true only if we have scheduled things right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no scheduling dependency here. coreTypeDiffs always contains all six core types (from Lamdera.Types.core), built via a zipWith3 in Check.hs. Every type flows through generateFor; the predicate is evaluated per-type. When onlyPreserveBackend is True, any type that isn't BackendModel evaluates to False regardless of the hashes, which causes coreTypeMigration to emit the Unchanged wrapper (line 194). The flag is purely a filter on which hash comparisons matter, not on what gets processed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, my question was to @miniBill comment "We probably also want BackendMsg here?"


coreMigrations :: [(N.Name, Migration)]
coreMigrations =
coreTypeDiffs
& fmap (\(t, oldHash, newHash) ->
(t, coreTypeMigration (oldHash /= newHash) oldVersion newVersion interfaces moduleName t iface_Types)
(t, coreTypeMigration (typeDidChange t oldHash newHash) oldVersion newVersion interfaces moduleName t iface_Types)
)
pure $ migrationsToFile migrationModuleText oldVersion newVersion coreMigrations moduleName

Expand Down