Consolidate all db schema changes in a single file

Handle all schema migrations through a single switch statement
where updates fall through. No need for loops or magic function
invocations.

The schema for the initial database setup was reverse engineered
by taking the old schema_install.sql (which was equivalent to v2.36's
schema) and unapplying all older changes as relevant (column type
changes were ignored since they become no-ops)

While at it, fix support for table name prefix: Both the database
initialization and later update steps failed here.

After every version, the php timeout is reset to 300 seconds.