SimonCropp/LocalDb

Some feedback/suggestions from just starting to experiment with this library.

Closed this issue ยท 20 comments

Is the feature request related to a problem

Not a problem, per say. These feature requests are about efficiently on-boarding and using this library.

Describe the solution

There were a few concepts and/or scenario's I wasn't sure how to do and if it's even possible. I did try to read the source code to get an understanding of:

  • what's happening under the covers
  • learn about undocumented API's which could resolve my scenario's.

Here's a list of questions/problems (in no particular order):

  • The difference between SqlInstance and SqlInstanceService. I noticed that SIS ends up creating a new instance of an SI, etc. but the README was vaugue on the differences and why one should be used of the other. I ended up reading source code to learn this. In fact, I thought it was a typo initially.
  • How to attach an existing database to the isolated test. The README just explains how to create a new DB and seed it with some data. I have an exisiting DB while many tables and relationships and even data. I totally understand that for a particular test you don't / shouldn't need other tables that aren't related to this test. But sometimes our tests do include multiple tables with relationships -and- a bit of fixed, real data. So it's easy to just use the .MDF file with some pre-seeded data, etc.
  • The method options of SqlInstance.Build(). There are xml comments that are provided with this method ๐ŸŽ‰ but I still found it ambiguous to grok. Possibly extend the documentation around this by provided some samples and explain why the various option values were provided (for those samples).
  • Sourcelink so we can step into the framework easily. I can even do a PR for this. EDIT: This .. actually worked? I was asked to download code from GH and .. it worked? I didn't see anything in AppVeyor for uploading snupkg .. hmm ... ah there is a sourcelink nuget in the csproj though! I missed that.

Describe alternatives considered

None.

Additional context

When I failed to create a SqlInstance I really enjoyed the error message provided, with steps to include how to clean up, afterwards. Nice. โœ…

Thanks again and looking forward to your thoughts/feedback.

EDIT: Sorcelink stuff, updated

Awesome feedback. Firstly do u use nunit or xunit?

The one and only unit-of-X ๐Ÿ˜Ž

I just deployed a v3 beta with some extra logging. https://github.com/SimonCropp/LocalDb/blob/master/pages/logging.md

Note the part about xunit

I removed sqlinstanceservice and updated the doco #10

Sourcelink should already be enabled. Is it not working? If so raise a new issue

I just deployed a v3 beta with some extra logging.

Cheers! I'll give this a try at a later date when I get some more bandwidth, next week.

I removed sqlinstanceservice

๐Ÿ‘Œ Cheers and noted!

Sourcelink should already be enabled. Is it not working? If so raise a new issue

It's working ๐Ÿ’ฏ % OK. I made an error when posted that the original issue post but corrected it a few minutes later ๐Ÿ˜Š

What I didn't understand was how the snupkg's where created and uploaded to nuget.org? When I looked at the .csproj' file I didn't see anything about creating snupkg's, or any artificats of this type created in the appveyor.yml.. let alongsnupkg`'s getting uploaded to nuget?

Does this answer any of your questions? https://github.com/SimonCropp/LocalDb/blob/master/pages/design.md

Yep! helps heaps!!

I was still hoping for some help on questions #2 and #3 (above)...

How to attach an existing database to the isolated test

can u give me some sample code of what you are trying to achieve?

re "The method options of SqlInstance.Build()" hows this https://github.com/SimonCropp/LocalDb/blob/master/pages/directory-and-name-resolution.md#database-name-resolution

Ah ... that's much better. Also, one more thing. I'm trying to remember what I was thinking/feeling when I first was learning this and now imagining if that new text, was the text I read for the first time.

A design goal is to have an isolated database per test. To facilitate this the SqlInstance.Build method has a convention based approach. It contains the following parameters:

So with that in mind (that is -> what would I think, if this was the first time I read this..) .. I'm wondering is something extra might add some further clarification.

e.g.

"A design goal is to have an isolated database per test. If one exists, then it is reused. If none exist, then one has to be created. To facilitate this the SqlInstance.Build method has a convention based approach. It contains the following parameters: "

(emphasis added to highlight my added suggestion).

Also -> i've not looked at the code to see what happens if the db exists, then what happens to the data/tables.

How to attach an existing database to the isolated test

can u give me some sample code of what you are trying to achieve?

I don't have any code that does this because I couldn't read any docs which explains if this is possible / how to do it.

If one exists, then it is reused. If none exist, then one has to be created.

but that is not correct. it always creates a new db, at least that is the experience of the consumer

How to attach an existing database to the isolated test

still struggling to groc what u need this for

But sometimes our tests do include multiple tables with relationships -and- a bit of fixed, real data. So it's easy to just use the .MDF file with some pre-seeded data, etc.

If u have a subset of tests that require different seed data. why not use a new instance of SqlInstance?

still struggling to groc what u need this for

It's sorta simplicity. Right now we have some databases with hundreds of rows of data. sometimes also with some table relationships (e.g. 1-1, 1-many) and Keys (FK's, PK's, etc). With the data, we sometimes go into the db and modify the rows to suit stuff we're trying.

So the thought was -> why not just grab this mdf and use it as a 'base template' and instead of (for each test) figuring out what to setup and seed, just use this same mdf for every test. Sure, it might contain more stuff than is required for that isolated test but the cost savings come when we don't have to tweak or setup any scripts for the "create-template" stage of a test .. i.e. the buildTemplate argument in the SqlInstance ctor.

sure, I wouldn't want to attach a 1GB mdf for each isolated test. but surely something smallish shouldn't be too bad? My guess here would be that for each test, the "base template mdf" would be copied (and renamed) and then attached. Indexes would all be ready to go, etc.

ok now i understand.

My guess here would be that for each test, the "base template mdf" would be copied (and renamed) and then attached. Indexes would all be ready to go, etc.

wouldnt that be pretty time consuming for a 1GB file?

wouldnt that be pretty time consuming for a 1GB file?

it would be hellish :( and I personally wouldn't do it. but if the mdf was 10mb or something small-and-pre-seeded, etc... that could be more managable. (I have no idea what size an mdf would be with 1000 or 100,000 rows in a table or over a number of tables, with some indexes.)

out of curiosity, do you currently have a scenario where you would use a pre-existing mdf file? or do u just think the feature should exist?

ok closing this one for now. can u raise a stand alone issue for using a pre-existing mdf file?

Morning - sorry, I've literally been off the grid for last 4 days (by design) and just got back on an hour ago.

do you currently have a scenario where you would use a pre-existing mdf file

Sure do. So I work on a project working with RealEstate (selling homes, renting properties, etc ... like Right Move). Sure we have millions of rows in various tables but I would love to strip 95% of the data out. Say -> keep 10k or 100k properties for .. say Greater London Shire, or Oxford Shire or Buckingham Shire (which is not 1x db table, but say 20x tables with indexes and keys and contraints) and use that for a large number of tests. I understand that there is a relationship between DB size and start up time (think -> I/O for copying/pasting) so it would be an experiment initially to play around with what feels nice .. versus ... manually coding all the data and 'seeding' it with every test run.

does this explain the build api sufficiently?

Yep - it does now. What really helped me understand that was when I used MS Management Studio to 'see' what the database looks like and I could then see all the db's that were manually, magically created. That really helped me grok things.