Xabaril / Esquio

Esquio is a Feature Toggle Library for .NET Developers.
Apache License 2.0
429 stars 49 forks source link

How do I initialize DB #89

Closed risogolo closed 4 years ago

risogolo commented 4 years ago

Trying to get empty DB tables created with Esquio.EntityFrameworkCore.Store I'm unable to do it, It seems to be created when I use that Esquio.UI, but I might dont want to use it Is it possible to automaticaly create DB if it does not exist, therefore I can use sql script or use EF migrations to insert data there


services.AddEsquio(setup =>
            {
                setup.RegisterTogglesFromAssemblyContaining<ClaimValueToggle>();
            }
                )
                .AddAspNetCoreDefaultServices()
                .AddEntityFrameworkCoreStore(options =>
                {
                    options.DefaultSchema = "RCM";
                    options.ConfigureDbContext = o => { o.UseSqlServer(Configuration["ConnectionStrings:MSSQLConnection"]); };
                });```
unaizorrilla commented 4 years ago

Hi @risogolo

Esquio UI, the free admin tool to manage Esquio products/features/toggles, initialize and migrate database to latest version. You can view migrate and seed on:

https://github.com/Xabaril/Esquio/blob/3edb71d683df4a4ba522e38f0ecebb1927ec768c/src/Esquio.UI/Program.cs#L14

This MigrateDbContext Extension method do migration and seed (if exist)

https://github.com/Xabaril/Esquio/blob/master/src/Esquio.UI/Infrastructure/Extensions/IHostExtensions.cs

If you plan to use database without UI, creating your own tool to admin products/features/toggles, you can add migrations ( dotnet ef migrations add ... ) from the EF configuration store to your project.

In Esquio 3.X, on development, we are chaning some things related with the store, all feedback is welcome for next version!!

Thanks Unai

risogolo commented 4 years ago

Hello, thank for you response, I guess that method should exist in the libray itself or in the library for SqlStore, not it in Esquio.UI, also if you are planning to change that please do also DB schema name configurable, as I seems the library can read the data from any schema name, currently it's defined by default in dbo and it's not easy to change it "from outside" of DbContext (from configurartion)

unaizorrilla commented 4 years ago

Hi risogolo!

Yeap, on V3 we are working on it, and probably, the store will be only for configuration and distributed ( to UI using http api ) because this enable distributed scenarios and also some multi-tenancy.

On 2.X you can use StoreOptions to configure default schema and table names

https://github.com/Xabaril/Esquio/blob/master/src/Esquio.EntityFrameworkCore.Store/Options/StoreOptions.cs

lurumad commented 4 years ago

Hi @risogolo

You can configure it using StoreOptions:

.AddEntityFrameworkCoreStore(options =>
                {
                    options.DefaultSchema = "yourschema";
                    options.ConfigureDbContext = (builder) =>
                    {
                        builder.UseSqlServer(Configuration.GetConnectionString("Esquio"));
                    };
                })

Regards!

risogolo commented 4 years ago

I guess this is where you set which schema to read from, but If I understand this correcly, currently the db tables are created only from UI project and there is no option to name the schema in which the tables will be created and I'm not able to seed the db currently without using UI, If I want to use just out of the box functionality. I know I can replicate the StoreDbContextSeed class into my project, but I believe this class should not be within UI project but within Esquio.EntityFrameworkCore.Store and this not contain an option for setting the schema name from outside

unaizorrilla commented 4 years ago

Yeap, I hope Esquio 3, we are planing to release in May solve this issue and improve the experience with this!

unaizorrilla commented 4 years ago

Already pushed on Esquio 3! Preview version are on NuGet right now!