Updating the EPSG database
---------------------------

The database in the zip file is a HSQL version of the official EPSG database.

0) Run the Decoder class in src/test/java/org/geotools/referencing/factory/epsg 
   and store the output for reference (it's the list of available code, and those that did not manage
   to decode, and why)    
1) Run the PropertyDumper class in src/test/java/org/geotools/referencing/factory/epsg and
   store the error messages somewhere for reference (it is the list of projections we don't support
   in the current version of the Geodetic DB)
2) Download from www.epsg.org the "geodetic dataset" creation scripts for the PostgreSQL database
3) Unzip them in _this_ directory, you should get three files named EPSG_v<version>.mdb_Data_PostgreSQL.sql,
   EPSG_v<version>.mdb_FKeys_PostgreSQL.sql and EPSG_v<version>.mdb_Tables_PostgreSQL.sql, where
   <version> is the the version of the EPSG database ("7_1" at the time of writing)  
4) Modify the PrepareForHSQL.xml file so that it points to the three files above 
5) Run the PrepareForHSQL.xml file:
   ant -f PrepareForHSQL.xml
   (or run it directly from Eclipse, this will work too and it's handier)
   This will create three new files, EPSG_Data.sql, EPSG_FKeys.sql and EPSG_Tables.sql whose
   content has been (mostly) amended to respect the HSQL syntax
6) Hand modify the EPSG_Tables.sql file so that the UNIQUE constraints are declared at the end
   of the table definition:
   
   Before:
   CREATE CACHED TABLE epsg_change (
    change_id     DOUBLE PRECISION NOT NULL UNIQUE,
    report_date   DATE NOT NULL,
    action        VARCHAR);
   
   After:
   CREATE CACHED TABLE epsg_change (
    change_id     DOUBLE PRECISION NOT NULL,
    report_date   DATE NOT NULL,
    action        VARCHAR,
    UNIQUE(CHANGE_ID) );
7) Update ThreadedHsqlEpsgFactory.VERSION to the current version
8) Run the DatabaseCreationScript.java
9) Check the EPSG.zip file has been updated
10) Run the build with extensive tests in the epsg-hsql module:
    mvn clean install -Pextensive.tests
   
    This step might force you to amend tests or modify the referencing subsystem to handle new
    axis direction definitions, new unit of measure and the like
11) Remove all the sql files in this directory, keeping only EPSG_Indexes.sql (which was already
    there when you started)
12) Run the Decoder class in src/test/java/org/geotools/referencing/factory/epsg again and compare
    the outputs with the previous one. If there is any code that used to decode properly, 
    but now does not, there is likely a regression to investigate.
12) Run the PropertyDumper class in src/test/java/org/geotools/referencing/factory/epsg again
    and compare the error messages. Sometimes EPSG changes the name of projections and the
    code thinks we do not support them anymore. If there is any new error check that it's not due
    just to a name change, if so, fix the projection Provider class accordingly.
    If errors occur fix them and rebuild.
13) Once everything is fixed run avagain the PropertyDumper and copy the output in the epsg-wkt
    module, updating it to the current version of the database. Mind, at the bottom of the 
    file there is a section commented as "#Extra Definitions Supplied from Community". This
    should be copied over from the old file and preserved.
14) Check the epsg-wkt history, there has been some manual changes for erreous TOWGS84 in the
    EPSG database, in particular for 28992. If the fix has not been yet incorportated in the
    EPSG database, run the manual fix (check the git file history for the corrected values).
15) Build GeoTools fully, and then GeoServer fully. This might point out other regressions or
    otherwise tests that need to be udpated, and as a result, PRs in GeoServer as well
16) Update the grid shift transformation pages at https://github.com/geoserver/geoserver/blob/master/doc/en/user/source/configuration/crshandling/coordtransforms.rst
    (the page source contains the queries to run)
17) Commit the changes and prepare PRs. Congratulations, you're done!


PostgreSQL notes
------------------------------

Sometimes it is handy to have the database loaded in PostgreSQL to run random queries
against it. In order to load it you'll have to change the psql encoding thought:
createdb epsg<version>
psql espg<version>
\encoding latin9
\i EPSG_v<version>.mdb_Tables_PostgreSQL.sql
\i EPSG_v<version>.mdb_Data_PostgreSQL.sql
\i EPSG_v<version>.mdb_FKeys_PostgreSQL.sql

     