Skip to content
This repository has been archived by the owner on Feb 13, 2019. It is now read-only.

Using web project with SQLite db without VS tooling #713

Closed
peterblazejewicz opened this issue May 14, 2016 · 9 comments
Closed

Using web project with SQLite db without VS tooling #713

peterblazejewicz opened this issue May 14, 2016 · 9 comments

Comments

@peterblazejewicz
Copy link
Member

peterblazejewicz commented May 14, 2016

How the users are supposed to start using web project - which uses SQLite - where there is no built-in automatic migration now?

The project builds, runs, but at the very first time where EF is to be used as backing store, the runtime exception will occur.

TBI

@rustd
@sayedihashimi

@peterblazejewicz
Copy link
Member Author

/cc
@natemcmaster

@rustd
Copy link

rustd commented May 14, 2016

What is the runtime exception? if you see an error page that tells you to apply migrations and refresh the page then it is expected. This is the same behavior as VS templates

@rustd
Copy link

rustd commented May 14, 2016

The generators should set the env to be development. This is what the VS templates do. Maybe ask the user at the time of project creation or output a message letting the user know that they should set the env to be development for dev only scenario.

@peterblazejewicz
Copy link
Member Author

peterblazejewicz commented May 15, 2016

The dotnet needs a simple solution for this.
/cc
@sayedihashimi

TL;DR;
@rowanmiller @glennc
It seems that using dotnet ef database update before dotnet run is enough to avoid all that mess. May I propose that we add this to generator-aspnet hints and into README.md as distinct diff from RC1? This will allow to still use default Production settings

  1. 'Production' is default, documented, can't be set because of implementation detail (consistent experience x-plat) I think
  2. I think the generator should install NPM and Bower deps now, if we expect that users will have to go into development mode at some point when running web templates. Most of the generators for web apps always do that on the end of project scaffolding

Notes:

  • by default no migration is applied to backing EF storage (compared to RC1)
  • everyone (except ones following changes in RC2 and Templates) will hit that problem when using Register/Login actions for the first time
  • by default 'Production' is enabled so after using Login/Register actions users see:
Error.
An error occurred while processing your request.
Development Mode
Swapping to Development environment will display more detailed information about the error that occurred.
Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.

NOTE> Even that information could be probably missing in next iteration. See: aspnet/Templates#560

  • so you have to switch to Development mode (unless you're smart enough to look into console output:
info: Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommandBuilderFactory[1]
      Executed DbCommand (462ms) [Parameters=[@__normalizedUserName_0='?'], CommandType='Text', CommandTimeout='30']
      SELECT "u"."Id", "u"."AccessFailedCount", "u"."ConcurrencyStamp", "u"."Email", "u"."EmailConfirmed", "u"."LockoutEnabled", "u"."LockoutEnd", "u"."NormalizedEmail", "u"."NormalizedUserName", "u"."PasswordHash", "u"."PhoneNumber", "u"."PhoneNumberConfirmed", "u"."SecurityStamp", "u"."TwoFactorEnabled", "u"."UserName"
      FROM "AspNetUsers" AS "u"
      WHERE "u"."NormalizedUserName" = @__normalizedUserName_0
      LIMIT 1
fail: Microsoft.EntityFrameworkCore.Query.RelationalQueryCompilationContextFactory[1]
      An exception occurred in the database while iterating the results of a query.
      Microsoft.Data.Sqlite.SqliteException: SQLite Error 1: 'no such table: AspNetUsers'.

but again, the templates are for noobs by design

export ASPNETCORE_ENVIRONMENT=Development
  • once restarted user have to explicitely cause the same error again to see solution (to see the solution break things again):
A database operation failed while processing the request.

AggregateException: One or more errors occurred. (SQLite Error 1: 'no such table: AspNetUsers'.) 
SqliteException: SQLite Error 1: 'no such table: AspNetUsers'. 
Applying existing migrations for ApplicationDbContext may resolve this issue
There are migrations for ApplicationDbContext that have not been applied to the database

00000000000000_CreateIdentitySchema
Apply Migrations

In Visual Studio, you can use the Package Manager Console to apply pending migrations to the database:

PM> Update-Database
Alternatively, you can apply pending migrations from a command prompt at your project directory:

> dotnet ef database update

@sayedihashimi
Copy link
Member

May I propose that we add this to generator-aspnet hints and into README.md as distinct diff from RC1?

Sounds great.

I think the generator should install NPM and Bower deps now, if we expect that users will have to go into development mode at some point when running web templates. Most of the generators for web apps always do that on the end of project scaffolding

If that's how most other generators work then lets do it.

I'm not sure about the ASPNETCORE_ENVIRONMENT env var issue. In VS we automatically set it to debug, but we can't really do that for command line users in the same way. Is this a problem for other frameworks and if so how do they solve it? When running yo aspnet for the first time, would it make sense to ask if users want us to update their profile to set the env var?

@peterblazejewicz
Copy link
Member Author

@sayedihashimi
OK

  • add hint for web (using SQLite) to run dotnet ef database udpate
  • add small NOTE into README why this is required
  • update postretore scripts to run: npm install && bower install as postrestore script
    I'll update RC2 with above ones

Thanks!

@natemcmaster
Copy link

Not sure what is in the templates, but this may be relevant:

When using SQLite with EF, relative connection strings are relative to the application base directory. e.g. "Filename=./blog.db". This directory changes with the upgrade from DNX to .NET Core CLI.

MyProject/  <-- the app base directory in DNX RC1
    project.json
    bin/
         Debug/
             netcoreapp1.0/   <--- the app base directory in .NET Core CLI Preview1
                   MyProject.dll 

If you are using .NET Core CLI and want to use a pre-existing sqlite db file, make sure your build options put the db file in the output path (project.json > "buildOptions" > "copyToOutput")

@peterblazejewicz
Copy link
Member Author

@natemcmaster

Not sure what is in the templates [...]

https://github.com/OmniSharp/generator-aspnet/blob/rc2/templates/projects/web/appsettings.json#L3

"ConnectionStrings": {
    "DefaultConnection": "Data Source=<%= namespace %>.db"
  },

and this is read by configuration builder (usual stuff).

peterblazejewicz added a commit to peterblazejewicz/generator-aspnet that referenced this issue May 16, 2016
See OmniSharp#713 comments about RC2 changes and avoiding
less experienced users confusion

Thanks!
peterblazejewicz added a commit to peterblazejewicz/generator-aspnet that referenced this issue May 16, 2016
See OmniSharp#713 comments about RC2 changes and avoiding
less experienced users confusion

Thanks!
peterblazejewicz added a commit to peterblazejewicz/generator-aspnet that referenced this issue May 16, 2016
See OmniSharp#713 comments about RC2 changes and avoiding
less experienced users confusion

Thanks!
peterblazejewicz added a commit to peterblazejewicz/generator-aspnet that referenced this issue May 16, 2016
See OmniSharp#713 comments about RC2 changes and avoiding
less experienced users confusion

Thanks!
peterblazejewicz added a commit that referenced this issue May 16, 2016
See #713 comments about RC2 changes and avoiding
less experienced users confusion

Thanks!
@peterblazejewicz
Copy link
Member Author

Closed via:
203dd97 and ecb2b27
Thanks!

peterblazejewicz added a commit to peterblazejewicz/generator-aspnet that referenced this issue May 16, 2016
See OmniSharp#713 comments about RC2 changes and avoiding
less experienced users confusion

Thanks!
peterblazejewicz added a commit that referenced this issue May 16, 2016
* Bring changes from aspnet/Templates#530 (#651)

* Remove comment from Main method in web templates (#645)

See aspnet/Templates/4521a05

* Address feedback for Startup.cs (#646)

See aspnet/Templates@53f174b

* Move Microsoft.NETCore.App to top of dependencies section (#647)

See aspnet/Templates@1a8c062

* Remove unneeded depenedencies from project.json (#648)

See aspnet/Templates@49173ba

* Move server gc section for full framework to app.config (#649)

See aspnet/Templates@289ac238

* 🐛 Remove a comma breaking config (#650)

* Fixed small formatting issue in RC2 info (#717)

Thanks to @horsdal!

* Bring changes from aspnet/Templates@37d8e90 (#652)

* ⬆️ Update web template to RC2

This commit brings file content changes
to web template (starter web with individual
authorization (in aspnet/Templates convention)
including:
- namespace changes
- project structure changes
- RC2 related structure additions
- assets changes
- client side deps updates
- test coverage update/rewrite
- client side assets updates
- SQLite EF updates

The template now restores, builds and
runs fine.
There are some small fixes remaining for
this tempalte to be done but they will
be part of separte review PR

* Add missing login partial import in web template (#655)

🐛 missing login partial import

* Fix SQLite connection string (#656)

The RC2 uses new convention for Configuration
access of connection strings. This commit
adopts that convention to construct and later
read SQLite configuration

* 🐛 Fix C#6 interpolation SQLite connection string (#658)

* 🐛 Fix $year$ variable artifact (#657)

* 🎨 Update Semantic UI option for web template to RC2 (#659)

👯

* 🐛 Fix invalid namespace in web template (#661)

Semantic UI version shipped with hardcoded namespace.
This commit fixes this

* Small fixes in Semantic UI version (#662)

- remove unused imports
- whitespace unification between versions

* 🔒 Always use HTTPS for MS url shortener (#663)

/cc @sayedihashimi

* Fix sections in starter web template (#664)

- section ordering

The sections are now sorted the same way as in
aspnet/Templates

* Add missing package declaration (#665)

* Small whitespace fix (#666)

* Fix whitespace to match aspnet/Templates version (#668)

* Add dnxcore50 import to console/lib project.json (#667)

See: aspnet/Templates#542

* Fix content layout of empty web app project.json (#669)

- sections layout
- scripts section content update

Thanks!

* Rename build options in configuration (#671)

See aspnet/Templates#536

* Fix missing package entry (#672)

* Revert "Rename build options in configuration (#671)" (#674)

This reverts commit 917740f.
The builds are failing under .NET Command Line Tools (1.0.0-rc2-002485)
starting from this commit.
The commit was found using git bisect tool:

917740f is the first bad commit
commit 917740f
Author: Peter Blazejewicz <[email protected]>
Date:   Fri May 6 22:19:05 2016 +0200

    Rename build options in configuration (#671)

    See aspnet/Templates#536

:040000 040000 1dcdfa62565e51d87aafd32b5b279df6b87570b0
db3df7d2f0358c095ab053c4d3be0f8c1749c8db M      templates

Thanks!

* Bring changes from aspnet/Templates#530 (#651) (#675)

* Remove comment from Main method in web templates (#645)

See aspnet/Templates/4521a05

* Address feedback for Startup.cs (#646)

See aspnet/Templates@53f174b

* Move Microsoft.NETCore.App to top of dependencies section (#647)

See aspnet/Templates@1a8c062

* Remove unneeded depenedencies from project.json (#648)

See aspnet/Templates@49173ba

* Move server gc section for full framework to app.config (#649)

See aspnet/Templates@289ac238

* 🐛 Remove a comma breaking config (#650)

* 📝 Update CLI animation in README.md. Closes #604 (#676)

- animation change
- framework name update in alt

Thanks!

* 📝 Update README.md. Closes #603 (#670)

- no code samples
- links to docs.asp.net instead of code samples

Thanks!

* Remove UseDefaultHostingConfiguration() from templates (#677)

Bring changes from aspnet/Templates@c749a4f
See also: aspnet/Announcements#174

Thanks!

* Remove duplicate section keys from configs (#678)

Duplicated sections removal
Thanks!

* Update/client side deps for RC2 (#681)

* ⬆️ Bump jQuery version

See aspnet/Templates#549

* ⬆️ Bump jQuery.Validation plugin

See aspnet/Templates#549

* React to project.json schema changes and tooling package renames (#679)

This bring some changes from aspnet/Templates@aa31cb9

Thanks!

* Output name field in Bower config in lowercase. Closes #680 (#682)

The name field meta key should be lower case
otherwise Bower renders a warning to users:
bower invalid-meta The "name" is recommended
to be lowercase, can contain digits, dots, dashes

The changes include:
- actual changes in bower.json templates
- test coverage

Thanks!

* Update/npm dependencies for RC2 (#683)

* ⬆️ Bump Gulp NPM dependency

After this change the version installed is 3.9.1:
npm install
...
├─┬ [email protected]
│ ├── [email protected]
│ ├─┬ [email protected]

Thanks!

* ⬆️ Bump up gulp-concat NPM version

npm install
└── [email protected]

Thanks!

* ⬆️ Bump gulp-uglify NPM version

npm install
...
└─┬ [email protected]

Thanks!

* ⬆️ Bump rimraf NPM version

npm install
...
└─┬ [email protected]
  └── [email protected]

Thanks!

* ⬆️ Bump Grunt NPM version

npm install
...
└─┬ [email protected]
  ├── [email protected]
  ├─┬ [email protected]

Thanks!

* Fix/launch settings (#684)

* 🐛 The launch settings use template variables

This commti fixes problems when launchSettings.json
has not been updated to evaluate project name used
in settings

Thanks!

* Fix missing launch settings

Make sure that changes from aspnet/Templates#521
are incorporated

* 🐛 Remove orphaned <text> tag. Fixes #553 (#687)

See aspnet/Templates#553 and aspnet/Templates#554

Thanks!

* Remove code for EF migration from Startup (#688)

This is follow up to aspnet/Templates#562

Thanks!

* Update Class Library template for RC2. Closes ##689 (#695)

Latest bits run on 1.0.0-rc2-002485

* Update Console application template. Closes #690 (#696)

This updates Console application template to RC2.
Tested on donet 1.0.0-rc2-002485

* Update Empty Web project template for RC2. Closes #691 (#697)

Tested and run using dotnet 1.0.0-preview1-002700

* Move mkdirp to regular dependencies (#699)

The mkdirp is technicaly runtime dependency for client
side installation - not development.
Is used by subgenerator and will be used by project
templates to create empty directories like wwwroot

Thanks!

* Update/web api app. Closes #692 (#700)

* 🎨 Store README.md in project root

The aspnet/Templates creates empty wwwroot web root
directory. This commits brings the same behavior
to generator. The readme is created in project root
while web root folder is created empty

Thanks!

* ⬆️ Update web api template for RC2

Udpated with recent changes from aspnet/Templates.
Tested and run on 1.0.0-preview1-002700

Thanks!

* Update NuGet unstable feeds to point to recent RC2 (#708)

* Update Console application template for RC2. Closes #706 (#709)

Most recent bits for final RC2
Tested with 1.0.0-preview1-002702

* Update Class Library project. Closes #705 (#710)

Update with most recent final RC2 bits
Thanks!

* Update WebAPI application for RC2. Closes #703 (#711)

The final bits of RC2
Tested with 1.0.0-preview1-002702

* Update Empty web application for RC2. Closes #704 (#712)

* Update Empty web application for RC2. Closes #704

Update with final bits for RC2

Tested with 1.0.0-preview1-002702

* 🎨 Store README.md project root

This moves README.md to the project root outside
of template webroot directory:
- implementation
- test coverage

This unifies template with aspnet/Templates structure

Thanks!

* ⬆️ Update web application template to aspnet. Closes #694 [WIP] (#702)

:arrow_up: Update web application template to aspnet. Closes #694

* ⬆️ Update starter web template for RC2. Closes #693 [WIP] (#701)

:arrow_up: Update starter web template for RC2. Closes #693

* [WIP] Update Unit test project for RC2. Closes #639 (#716)

Update Unit test project for RC2. Closes #639

* Call NPM and Bower install scripts in postrestore (#718)

See #713 comments about RC2 changes and avoiding
less experienced users confusion

Thanks!

* Add EF migration usage hints for RC2 web template (#719)

EF migrations are now not built-into templates
let users to know how to scaffold database using code-first scenario
with saved migrations
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants