News for hackers. Stuff that matters.
Re:SQL is 43 years old – Here’s why we still use it today by cafard on Tuesday May 02, 2017 @09:00AM (#14245957)
Show me your well-defined normalized tables, and I will know the rules for a valid state of the system. How, though, will I know the rules for a valid transition from one state to another? Have I seen some nasty stored procedures? Yes, a number of which I have written. But I have seen well thought out and useful ones also.
Re:SQL is 43 years old – Here’s why we still use it today by scarface74 on Tuesday May 02, 2017 @09:21AM (#14246102)
With logic being in code:

* it is easily unit tested

* all source code is one place that can be branched, versioned, merged, deployed, rolled back, diffed, code reviewed, approved with pull request etc.

Re:SQL is 43 years old – Here’s why we still use it today by duozerk on Tuesday May 02, 2017 @12:05PM (#14247571)
Or you can simply implement it so that when your code runs it first checks that the stored procedures exist and have the same definition as the one stored in the source code; and to drop/recreate them if that's not the case.

In which case the stored procedures are in your "main" code repo and "deploying" them simply means running the software. Though your point about unit tests stands.

Re:SQL is 43 years old – Here’s why we still use it today by adaml_623 on Tuesday May 02, 2017 @09:35AM (#14246178)
Why are your stored procedures not in the code repo?
Re:SQL is 43 years old – Here’s why we still use it today by lmm on Tuesday May 02, 2017 @10:56AM (#14246834)
Because deployment tooling for stored procedures sucks?
Re:SQL is 43 years old – Here’s why we still use it today by jamra on Tuesday May 02, 2017 @01:15PM (#14248317)
Stored procedures are easier to deploy than table schema. You just need to drop if exists and then create them.

Table schema is the hard part since there is overhead associated with creating an index on an existing table and with renaming a column.

Re:SQL is 43 years old – Here’s why we still use it today by spacemanmatt on Tuesday May 02, 2017 @09:44AM (#14246229)
SQL is code. Not sure how that escapes people.
Re:SQL is 43 years old – Here’s why we still use it today by scarface74 on Tuesday May 02, 2017 @10:54AM (#14246823)
Harder to unit test, harder to merge, harder to roll back...
Re:SQL is 43 years old – Here’s why we still use it today by self-diversity on Tuesday May 02, 2017 @12:59PM (#14248148)
That was true a decade ago. The tooling has caught up in most languages, so it's trivial to embed your SQL in application code and use it in an environmentally independent matter (eg to invoke in unit tests), provided you take the few minutes initially to set things up correctly instead of the all-too-common "fuck it we're a startup" manner people seem to love.
Re:SQL is 43 years old – Here’s why we still use it today by agentultra on Tuesday May 02, 2017 @09:55AM (#14246307)
And you can unit test it too.

http://pgtap.org

Re:SQL is 43 years old – Here’s why we still use it today by scarface74 on Tuesday May 02, 2017 @10:12AM (#14246446)
Guess which is faster for continuous testing - being able to mock out your Entity Framework context and use an in memory representation of your table via Lists or constantly running an ungodly stored proc against the database?
Re:SQL is 43 years old – Here’s why we still use it today by agentultra on Tuesday May 02, 2017 @12:09PM (#14247606)
I can't say that our tests are slow. We can test our database continuously and independently from our various projects that utilize it. Our integration and smoke tests run continuously as you would expect.
Re:SQL is 43 years old – Here’s why we still use it today by scarface74 on Tuesday May 02, 2017 @12:40PM (#14247947)
You can't tell me that you can run a full suite of database dependent tests as you can run a bunch of in memory tests that mock the database queries.

How do you handle 5 - 10 devs working concurrently if they are all running tests?

Re:SQL is 43 years old – Here’s why we still use it today by jamra on Tuesday May 02, 2017 @01:17PM (#14248339)
You work from local databases. You keep a migration script that sets up the schema and another migration script that sets up the data. If you create a feature, you must add to each script when merging.

You can run unit tests by creating transactions, running the test, and then rolling back at the end.

I do get your point, though. It's more convenient to be able to mock your database from your code.

Re:SQL is 43 years old – Here’s why we still use it today by scarface74 on Tuesday May 02, 2017 @01:37PM (#14248567)
That's much more complicated than just mocking your context in unit tests....

https://msdn.microsoft.com/en-us/library/dn314429(v=vs.113)....

Go down to "Testing Query Scenerios". I've wrapped the four "mockset.As" lines into one extension method to make it a lot less verbose.

Re:SQL is 43 years old – Here’s why we still use it today by jamra on Tuesday May 02, 2017 @02:08PM (#14248909)
Yes it is, but it's much less complicated than trying to guess what your generated SQL code will look like.
Re:SQL is 43 years old – Here’s why we still use it today by scarface74 on Tuesday May 02, 2017 @02:49PM (#14249347)
No need to guess. Run all of your unit tests without mocking out your DbContext and add the following ....

context.Database.Log = log.Info

Where Log.info is just a method that accepts a string and take a look at the log file generated from your unit tests.

Re:SQL is 43 years old – Here’s why we still use it today by agentultra on Tuesday May 02, 2017 @01:15PM (#14248318)
Isolation I guess? I don't know what your experience is and why you think it cannot be anything but slow but... it's not?

pgtap lets us unit test our SQL functions, triggers, views, etc. It's integrated with our change management system. It's fast enough and works well.

Re:SQL is 43 years old – Here’s why we still use it today by spacemanmatt on Tuesday May 02, 2017 @09:47AM (#14246250)
I like to use table-driven transition constraints. The basic design is, you have a table of valid transitions (begin state, end state) and a function that you can write a constraint with.

It's the same as other code, but with better data locality.