Why is there no initiallyDeferred parameter on Liquibase addNotNullConstraint? - liquibase

Any reason why Liquibase's addNotNullConstraint doesn't have an attribute initiallyDeferred?
addForeignKeyConstraint and addUniqueConstraint both have an attribute initiallyDeferred.

I think this is just a missing feature. Liquibase has very few people contributing code, so sometimes things just aren't done yet. My company (Datical) has been making efforts to improve that, but we still rely very heavily on the users of Liquibase to point out where there are shortcomings.
I have created a jira ticket (CORE-3024) to track this.

Related

What/Who writes changeset in liquibase change logs?

It might be super obvious but no one bothered clarifying what or who is actually creating/writing the changesets for liquibase. I read more than a dozen articles related to changesets in liquibase and while I now understand how it works I still wonder if these changesets are generated somewhere by Liquibase ? Or are users supposed to write them by hand ?
And do we agree that the CHANGELOGTABLE, is populated from doing a liquibase update by reading the already existing changesets ? Not the other way around ?
And do we also agree that liquibase doesn't track schema changes, it just computes the desired state of a DB from the changesets ?
Thanks
Edit: I asked many questions, but ultimately I'm just looking for an answer to the title and somehow understand properly how liquibase works.
You write the changeset. And since you can write changesets in sql, its just you writing the database scripts your application needs.
Yes, the DATABASECHANGELOG table is the audit log that gets written after a liquibase update that shows what changesets got executed.
I would recommend taking the fundamentals course provided for free at Liquibase University that covers these very basic concepts. Without it, it will be much harder to be successful using Liquibase. My experience: You can pretty much finish the course in one sitting or maybe an hour each day for a few days.

Data Migrations on Production Database

Is there any way to have data migrations on production database not to be with SQL?
We are using MigratorDotNet and when we build a new funcionality for the application that changes the scheme of the database and we need to do some data updates we have to do this complex and troublesome SQL statements so the data is consistent on production.
Was wondering if there was another way to do this, what are the bests practices to do this? Any ideas on other possible solutions?
We cannot use something like NHibernate because then we have to keep fixing old migrations when the scheme changes, and that can be error prone.
The trick is to use your migration tool and fold said data manipulation statements into the migrations. We use an extended version of the same thing typically for a few projects and it can definitely handle that trick.
If you're already using a migration tool like Migrator.NET then I'd say you're most of the way there. Complex schema/data changes are just a fact of life in the RDBMS world.
Try mite. It let's you do anything that you can do with sql and use sql to do it but have the ability to ensure your database is on the desired version and not risk executing a script that has already run (or miss a script), leaving your database in a consistent state.
If your developers adopt this. Deployments are a simple mite update and then you know problems are product related or data related (but not schema related).
https://github.com/soitgoes/mite
Let me know what you think. I developed this and have been using this with my team for years with great success.

Getting Started with Fluent NHibernate

I'm trying to get into using Fluent NHibernate, and I have a couple questions. I'm finding the documentation to be lacking.
I understand that Fluent NHibernate / NHibernate allows you to auto-generate a database schema. Do people usually only do this for Test/Dev databases? Or is that OK to do for a production database? If it's ok for production, how do you make sure that you're not blowing away production data every time you run your app?
Once the database schema is already created, and you have production data, when new tables/columns/etc. need to be added to the Test and/or Production database, do people allow NHibernate to do this, or should this be done manually?
Is there any REALLY GOOD documentation on Fluent NHibernate? (Please don't point me to the wiki because in following along with the "Your first project" code building it myself, I was getting run-time errors because they forget to tell you to add a reference. Not cool.)
Thanks,
Andy
I've been using Fluent NHibernate Automapping for a few months now. I'm by no means an expert, but can take a stab at your questions...
FNH Automapping does indeed create DB schemas from POCO classes, including lists of other objects (this was the reason I chose NHibernate in the first place).
When you change schemas, you have to rerun the automapping, which does drop the whole database, unfortunately. In my case, it's not a big problem because I'm importing existing binary data files, so I just have to re-import my data every time the schema changes. I've read that there's some data migration support available with NHibernate, but have no experience with this. (BTW, Subsonic will do data migration, but it's automapping functionality is far more rudimentary - at least it was when I evaluated it a few months ago)
FNH documentation is one of my pet peeves - they have not even added Intellisense help on the method names, etc. (But they get really huffy when you point that out - ask me how I know!) I've made a couple of edits to the wiki when I could, but there's so much more that could be done there. The best approach is to start with a working example (i.e.
this one from Nikola Malovic, and post questions to the support form if (when!) you run into trouble. In general, I've found the FNH community pretty helpful, and have been able to work through all my difficulties. They've also fixed a couple of bugs I've found.
Overall, using FNH has been a huge win for my project - highly recommended!
I don't use Fluent, but I can help with classic NHibernate.
yes, the creation of the schema is very recommendable for production use (Schema Export). When you do this is up to you. For instance, you could create the database by an installer. You shouldn't drop existing databases, but this is a decision of you application.
I don't understand this question. Do you mean you need to upgrade an existing database to a new database schema? This is unfortunately something you need to implement yourself. NH can't do much about this, because it is very specific to you data and the changes you made. There is also a Schema Update or something like this, which is not recommended for production use.
I don't use Fluent, so I can't help here.

ORM & Logical Delete

Do any of the available ORMs support using a bit field to represent row removal?
More information. Working in C#. I need to delete this way to support synchronization of remote database changes to a central database. I'm looking for a possible ORM, but am also interested in approaches to the problem. So if anyone knows any ORM in any language/environment that addresses this problem I would be interested in looking at it. Thanks for the questions feel free to ask more if anything is unclear.
This may not apply if you're not using .NET, but the LightSpeed ORM has a built in feature called "soft delete". Basically, when you have a DeletedOn field on your table LightSpeed will insert the time it was deleted. It automatically handles this on normal selects (e.g. where Deleted == null) so that the deleted items are not seen again. You could then write a sync process that detects the deleted state by checking that field.
You can of course instruct the querying engine to include deleted results.
Mindscape LightSpeed ORM
I am making an assumption also that we're talking about the same thing here :-)
I recommend to implement logical delete externally in your application, cause it's not very complex, but it will be more flexible. See this article for details.

Nhibernate and History Tables

I am working on a ASP.NET MVC website using Nhibernate as my ORM. The project is similar to a wiki/blog engine and requires that as pages are edited they store a history of the edits in another table which can then be viewed and recovered. This is complicated somewhat in that each "page" can have collections associated with it that can also be edited/added/removed. I would also need to stored these changes.
I was wondering how this fits into an entity mapping scenario such as Nhibernate and how this might be implemented. If anyone knows of any articles on this, or has done this themselves then please let me know.
I was considering triggers but I would prefer not to mix data access technologies if possible. I also am using MySql so CDC would not be possible for me.
Thanks
Either implement an auditing interceptor or use the event system. The event system is newer, I haven't found any auditing examples yet...
Also see this related question:
Take a look at NHibernate.Envers https://bitbucket.org/RogerKratz/nhibernate.envers