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
26 changes: 17 additions & 9 deletions extra/Lamdera/Evergreen/MigrationGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ coreTypeMigration typeDidChange oldVersion newVersion interfaces newModule typeN

(Just typeDefOld@(Union mOld typeNameOld unionOld), Just (Union mNew typeNameNew unionNew)) -> do
let
unionDefMigration = migrateUnionDefinition typeDefOld oldVersion newVersion newModule identifier typeName interfaces recursionSet [] [] unionNew
unionDefMigration = migrateUnionDefinition typeDefOld oldVersion newVersion newModule identifier typeNameOld interfaces recursionSet [] [] unionNew

(MigrationNested migrationImpl imps subDefs) = unionDefMigration
migration = T.concat ["\n ", migrationWrapperForType typeName, " ( ", migrationImpl, " old, Cmd.none )"]
Expand All @@ -193,16 +193,18 @@ coreTypeMigration typeDidChange oldVersion newVersion interfaces newModule typeN

-- A top level Custom Type definition i.e. `type Herp = Derp ...`
migrateUnionDefinition :: TypeDef -> Int -> Int -> ModuleName.Canonical -> TypeIdentifier -> N.Name -> Interfaces -> RecursionSet -> TvarMap -> TvarMap -> Can.Union -> Migration
migrateUnionDefinition typeDefOld oldVersion newVersion scope identifier@(author, pkg, newModule, tipe) typeNameNew interfaces recursionSet tvarMapOld tvarMapNew newUnion =
migrateUnionDefinition typeDefOld oldVersion newVersion scope identifier@(author, pkg, newModule, tipe) typeNameOld interfaces recursionSet tvarMapOld tvarMapNew newUnion =
let typeNameNew = tipe
in
case typeDefOld of
(Alias moduleNameOld typeNameOld aliasOld) ->
(Alias moduleNameOld typeNameOld_ aliasOld) ->
unimplemented "" ("`" <> N.toText typeNameNew <> "` was a type alias, but now it's a custom type. I need you to write this migration.")
(Union moduleNameOld typeNameOld unionOld) ->
migrateUnionDefinition_ author pkg unionOld newUnion tvarMapOld tvarMapNew oldVersion newVersion typeNameNew newModule identifier (dropCan moduleNameOld) interfaces recursionSet scope
(Union moduleNameOld typeNameOld_ unionOld) ->
migrateUnionDefinition_ author pkg unionOld newUnion tvarMapOld tvarMapNew oldVersion newVersion typeNameOld typeNameNew newModule identifier (dropCan moduleNameOld) interfaces recursionSet scope


migrateUnionDefinition_ :: Pkg.Author -> Pkg.Project -> Can.Union -> Can.Union -> TvarMap -> TvarMap -> Int -> Int -> N.Name -> N.Name -> TypeIdentifier -> N.Name -> Interfaces -> RecursionSet -> ModuleName.Canonical -> Migration
migrateUnionDefinition_ author pkg oldUnion newUnion tvarMapOld tvarMapNew oldVersion newVersion typeName newModule identifier oldModuleName interfaces recursionSet scope =
migrateUnionDefinition_ :: Pkg.Author -> Pkg.Project -> Can.Union -> Can.Union -> TvarMap -> TvarMap -> Int -> Int -> N.Name -> N.Name -> N.Name -> TypeIdentifier -> N.Name -> Interfaces -> RecursionSet -> ModuleName.Canonical -> Migration
migrateUnionDefinition_ author pkg oldUnion newUnion tvarMapOld tvarMapNew oldVersion newVersion typeNameOld typeName newModule identifier oldModuleName interfaces recursionSet scope =
let
oldModuleNameCanonical :: ModuleName.Canonical
oldModuleNameCanonical = ModuleName.Canonical (Pkg.Name author pkg) oldModuleName
Expand Down Expand Up @@ -276,7 +278,7 @@ migrateUnionDefinition_ author pkg oldUnion newUnion tvarMapOld tvarMapNew oldVe
migrationTypeSignature = T.concat
[ paramMigrationFnsTypeSig & T.intercalate " -> " & suffixIfNonempty " -> "
, " "
, oldModuleName & N.toText, ".", typeName & N.toText
, oldModuleName & N.toText, ".", typeNameOld & N.toText
, " "
, tvarsOld & fmap (\tvar -> T.concat [N.toText tvar, "_old"]) & T.intercalate " "
, " -> "
Expand Down Expand Up @@ -920,6 +922,12 @@ typeToMigration oldVersion newVersion scope interfaces recursionSet_ typeNew@(Ca
canToMigration oldVersion newVersion scope interfaces newRecursionSet p0 (Just (p0o)) tvarMapOld tvarMapNew anonymousValueRef
in
T.concat [ "(\\", anonymousValueRef, " -> ", migration, ")"]
else if not (T.isPrefixOf "(" migrate_p0) && "|>" `T.isInfixOf` migrate_p0 then
-- Raw pipeline migrations (e.g. nested Dict/SeqDict) must be wrapped
-- in a lambda so they can be passed as function arguments to
-- Tuple.mapBoth, List.map, etc. Already-parenthesised expressions
-- (e.g. lambdas like `(\(t1,t2,t3) -> ...)`) are skipped.
T.concat [ "(\\v__ -> v__ |> ", migrate_p0, ")" ]
else
T.concat [ migrate_p0 ]

Expand Down Expand Up @@ -1051,7 +1059,7 @@ migrateTypeDef typeOld typeNew oldVersion newVersion interfaces tvarMapOld tvarM
in
-- @TODO use unionOld instead of typeDefOld
-- @TODO pass params
migrateUnionDefinition typeDefOld oldVersion newVersion mNew identifier typeNameNew interfaces newRecursionSet tvarMapOld tvarMapNew unionNew
migrateUnionDefinition typeDefOld oldVersion newVersion mNew identifier typeNameOld interfaces newRecursionSet tvarMapOld tvarMapNew unionNew
& debugMigrationIncludes_ "migrateTypeDef:Union" (typeOld, typeNew)

-- @ADVANCED handle case where user is aliasing a custom type?
Expand Down
2 changes: 2 additions & 0 deletions test/Test/Lamdera/Evergreen/TestMigrationGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ testExamples = withTestEnv $ do
-- , "src/Test/Migrate_External_Wrap.elm"
"src/Migrate_External_Paramed"
, "src/Migrate_All"
, "src/Migrate_Union_Renamed"
, "src/Migrate_Nested_Dict"
]

catchTestException :: FilePath -> SomeException -> IO a
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Migrate_Nested_Dict.Actual exposing (..)

{-| This migration file was automatically generated by the lamdera compiler.

It includes:

- A migration for each of the 6 Lamdera core types that has changed
- A function named `migrate_ModuleName_TypeName` for each changed/custom type

Expect to see:

- `Unimplementеd` values as placeholders wherever I was unable to figure out a clear migration path for you
- `@NOTICE` comments for things you should know about, i.e. new custom type constructors that won't get any
value mappings from the old type by default

You can edit this file however you wish! It won't be generated again.

See <https://dashboard.lamdera.app/docs/evergreen> for more info.

-}

import Lamdera.Migrations exposing (..)
import Migrate_Nested_Dict.New
import Migrate_Nested_Dict.Old


target =
migrate_Migrate_Nested_Dict_New_Target


migrate_Migrate_Nested_Dict_New_Target : Migrate_Nested_Dict.Old.Target -> Migrate_Nested_Dict.New.Target
migrate_Migrate_Nested_Dict_New_Target old =
case old of
Migrate_Nested_Dict.Old.Wrapper p0 ->
Migrate_Nested_Dict.New.Wrapper (p0 |> Dict.toList |> List.map (Tuple.mapBoth (Unimplemented {- Type changed from `Int` to `String`. I need you to write this migration. -}) (Dict.toList |> List.map (Tuple.mapFirst (Unimplemented {- Type changed from `Int` to `String`. I need you to write this migration. -})) |> Dict.fromList)) |> Dict.fromList)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Migrate_Nested_Dict.Expected exposing (..)

{-| This migration file was automatically generated by the lamdera compiler.

It includes:

- A migration for each of the 6 Lamdera core types that has changed
- A function named `migrate_ModuleName_TypeName` for each changed/custom type

Expect to see:

- `Unimplementеd` values as placeholders wherever I was unable to figure out a clear migration path for you
- `@NOTICE` comments for things you should know about, i.e. new custom type constructors that won't get any
value mappings from the old type by default

You can edit this file however you wish! It won't be generated again.

See <https://dashboard.lamdera.app/docs/evergreen> for more info.

-}

import Lamdera.Migrations exposing (..)
import Migrate_Nested_Dict.New
import Migrate_Nested_Dict.Old


target =
migrate_Migrate_Nested_Dict_New_Target


migrate_Migrate_Nested_Dict_New_Target : Migrate_Nested_Dict.Old.Target -> Migrate_Nested_Dict.New.Target
migrate_Migrate_Nested_Dict_New_Target old =
case old of
Migrate_Nested_Dict.Old.Wrapper p0 ->
Migrate_Nested_Dict.New.Wrapper (p0 |> Dict.toList |> List.map (Tuple.mapBoth (Unimplemented {- Type changed from `Int` to `String`. I need you to write this migration. -}) (\v__ -> v__ |> Dict.toList |> List.map (Tuple.mapFirst (Unimplemented {- Type changed from `Int` to `String`. I need you to write this migration. -})) |> Dict.fromList)) |> Dict.fromList)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Migrate_Nested_Dict.New exposing (..)

import Dict exposing (Dict)


type Target
= Wrapper (Dict String (Dict String Int))
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Migrate_Nested_Dict.Old exposing (..)

import Dict exposing (Dict)


type Target
= Wrapper (Dict Int (Dict Int Int))
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module Migrate_Union_Renamed.Actual exposing (..)

{-| This migration file was automatically generated by the lamdera compiler.

It includes:

- A migration for each of the 6 Lamdera core types that has changed
- A function named `migrate_ModuleName_TypeName` for each changed/custom type

Expect to see:

- `Unimplementеd` values as placeholders wherever I was unable to figure out a clear migration path for you
- `@NOTICE` comments for things you should know about, i.e. new custom type constructors that won't get any
value mappings from the old type by default

You can edit this file however you wish! It won't be generated again.

See <https://dashboard.lamdera.app/docs/evergreen> for more info.

-}

import Lamdera.Migrations exposing (..)
import Migrate_Union_Renamed.New
import Migrate_Union_Renamed.Old


target =
migrate_Migrate_Union_Renamed_New_Target


migrate_Migrate_Union_Renamed_New_CompanyType : Migrate_Union_Renamed.Old.CompanyType -> Migrate_Union_Renamed.New.CompanyType
migrate_Migrate_Union_Renamed_New_CompanyType old =
case old of
Migrate_Union_Renamed.Old.Individual ->
Migrate_Union_Renamed.New.Individual

Migrate_Union_Renamed.Old.Corporation ->
Migrate_Union_Renamed.New.Corporation


migrate_Migrate_Union_Renamed_New_Target : Migrate_Union_Renamed.Old.Target -> Migrate_Union_Renamed.New.Target
migrate_Migrate_Union_Renamed_New_Target old =
case old of
Migrate_Union_Renamed.Old.Wrapper p0 ->
Migrate_Union_Renamed.New.Wrapper (p0 |> migrate_Migrate_Union_Renamed_New_CompanyType)
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module Migrate_Union_Renamed.Expected exposing (..)

{-| This migration file was automatically generated by the lamdera compiler.

It includes:

- A migration for each of the 6 Lamdera core types that has changed
- A function named `migrate_ModuleName_TypeName` for each changed/custom type

Expect to see:

- `Unimplementеd` values as placeholders wherever I was unable to figure out a clear migration path for you
- `@NOTICE` comments for things you should know about, i.e. new custom type constructors that won't get any
value mappings from the old type by default

You can edit this file however you wish! It won't be generated again.

See <https://dashboard.lamdera.app/docs/evergreen> for more info.

-}

import Lamdera.Migrations exposing (..)
import Migrate_Union_Renamed.New
import Migrate_Union_Renamed.Old


target =
migrate_Migrate_Union_Renamed_New_Target


migrate_Migrate_Union_Renamed_New_CompanyType : Migrate_Union_Renamed.Old.MoralType -> Migrate_Union_Renamed.New.CompanyType
migrate_Migrate_Union_Renamed_New_CompanyType old =
case old of
Migrate_Union_Renamed.Old.Individual ->
Migrate_Union_Renamed.New.Individual

Migrate_Union_Renamed.Old.Corporation ->
Migrate_Union_Renamed.New.Corporation


migrate_Migrate_Union_Renamed_New_Target : Migrate_Union_Renamed.Old.Target -> Migrate_Union_Renamed.New.Target
migrate_Migrate_Union_Renamed_New_Target old =
case old of
Migrate_Union_Renamed.Old.Wrapper p0 ->
Migrate_Union_Renamed.New.Wrapper (p0 |> migrate_Migrate_Union_Renamed_New_CompanyType)
10 changes: 10 additions & 0 deletions test/scenario-migration-generate/src/Migrate_Union_Renamed/New.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Migrate_Union_Renamed.New exposing (..)


type Target
= Wrapper CompanyType


type CompanyType
= Individual
| Corporation
10 changes: 10 additions & 0 deletions test/scenario-migration-generate/src/Migrate_Union_Renamed/Old.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Migrate_Union_Renamed.Old exposing (..)


type Target
= Wrapper MoralType


type MoralType
= Individual
| Corporation