Fixed #20968 -- Checked Spatialite metadata before migrations

Thanks Kenial S. Lee for the initial patch and Tim Graham for
the review.
Ran 'CREATE EXTENSION postgis' during prepare_database hook

DatabaseWrapper.prepare_database has been introduced in 307de67073.