diff --git a/AzureCodeCamp/PancakeProwler.Data.Postgres/Repositories/RecipeRepository.cs b/AzureCodeCamp/PancakeProwler.Data.Postgres/Repositories/RecipeRepository.cs index d3cea35..310bb35 100644 --- a/AzureCodeCamp/PancakeProwler.Data.Postgres/Repositories/RecipeRepository.cs +++ b/AzureCodeCamp/PancakeProwler.Data.Postgres/Repositories/RecipeRepository.cs @@ -9,7 +9,7 @@ namespace PancakeProwler.Data.Postgres.Repositories { - public class RecipeRepository : IRecipeRepository + public class RecipeRepository : IRecipeRepository, IPostgresRepository { public IEnumerable List() { @@ -39,5 +39,25 @@ public Recipe GetById(Guid id) private string ConnectionString { get { return ConfigurationManager.ConnectionStrings["Postgres"].ConnectionString; } } + + public void InitPostgresStorage() + { + var sql = @"DROP TABLE IF EXISTS recipes; +CREATE TABLE recipes +( + ""id"" uuid NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000'::uuid, + ""name"" text NOT NULL DEFAULT ''::text, + ""contributor"" text, + ""ingredients"" text, + ""steps"" text, + ""image_location"" text, + CONSTRAINT ""pk_recipes"" PRIMARY KEY (""id"") +);"; + using ( var conn = new NpgsqlConnection( ConnectionString ) ) + { + conn.Open(); + conn.Execute(sql); + } + } } }