0

I am working on a C# winformsapp and I have an SQLite db that I access using Entity Framework. I am about to release v1.0 of the software.

My question is: when I am developing v1.1, I may need to add new fields to the database. Of course, I want users to be able to copy their data over from v1.0, but if they just copied over the database file, EF would surely give an exception when it tries to access the new fields that don't exist.

Do I have to create an 'Import database from v1.0' function that copies the data from the old database and inserts into the new database? I feel like this would take too long. Can I just create a function that modifies the old database directly, using EF or otherwise?

shadowsora
  • 663
  • 7
  • 15
  • 2
    Why would you create a new database? Why not just modify the existing database to meet your needs? Write a migration script for it. – mason Nov 13 '17 at 17:36
  • 1
    EF can handle [migrations](https://msdn.microsoft.com/en-us/library/jj591621(v=vs.113).aspx) *<= see link*. – Igor Nov 13 '17 at 17:38
  • As your question is fairly broad let me know if this is not what you are looking for. – Igor Nov 13 '17 at 17:46
  • @Igor I think that might be what I am after. Does it matter that my db is not code first? I created it in SQLiteStudio. – shadowsora Nov 13 '17 at 20:30
  • You mean you are using the designer (.edmx)? – Igor Nov 14 '17 at 12:18
  • @Igor I created the database file using a third party GUI for creating SQLite databases. Then created the .edmx model by connecting to that database file in Visual Studio. – shadowsora Nov 15 '17 at 13:06

1 Answers1

1

Typically, the way I've done this...

  1. Create a copy of your existing database. Make this your "dev" database
  2. Change your database as needed and complete version 1.1 of your program, using this "dev" database.
  3. When you are ready, use a database differencing tool, such as SqlDiff or SQL Compare, to create differencing scripts.
  4. Backup your live database.
  5. Run these differencing scripts against your live database. This should add your new fields, tables, views, etc, to the live database.
  6. You're good to go
Icemanind
  • 47,519
  • 50
  • 171
  • 296
  • My app is run locally with a local database file on each user's machine. By "live database", do you mean the ones on their machines? So, I should create the differencing scripts and add some functionality in 1.1 that will run the scripts if it detects a previous database from 1.0? – shadowsora Nov 13 '17 at 20:27
  • @shadowsora - By "live" database, I mean a copy of your 1.0 database. Just in case you have to revert back. And yes, as part of your setup program for 1.1, the 1.1 setup should run the differencing scripts, which will upgrade the user's database to the new version. I recommend having the setup back up the user's database before running the differencing scripts, just in case. – Icemanind Nov 14 '17 at 13:41