namespace Migrations

open SimpleMigrations

[<Migration(201910131209L, "Create Recipes")>]
type CreateRecipes() =
    inherit Migration()

    override __.Up() = base.Execute(@"
    CREATE TABLE Recipes(
      id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
      nameFi VARCHAR NOT NULL,
      nameEn VARCHAR NOT NULL,
      durationMin INT NOT NULL,
      durationMax INT NOT NULL,
      origin VARCHAR,
      steps VARCHAR ARRAY NOT NULL
    );

    CREATE TABLE RecipeIngredients(
      recipeId INTEGER NOT NULL REFERENCES Recipes,
      ingredientId INTEGER NOT NULL REFERENCES Ingredients,
      modifier VARCHAR,
      quantity NUMERIC(5,2),
      unit VARCHAR,

      PRIMARY KEY (recipeId, ingredientId)
    )")

    override __.Down() = base.Execute(@"DROP TABLE RecipeIngredients; DROP TABLE Recipes")
