Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Add db upgrade script #142

Krinkle opened this Issue · 5 comments

3 participants



  • Ask confirmation (skippable) that all data (other than user accounts) may be lost
  • init.php
  • Query users table (keep in memory)
  • Clear all tables (needs to be in a certain order due to foreignkey restrictions)
  • Drop all tables (including indices and foreignkey restrictions)
  • Run testswarm.sql
  • Run useragents.sql
  • Insert rows back into users table
  • Finish

instead of
"Clear all tables (needs to be in a certain order due to foreignkey restrictions)"
you could disable keys at first, so there will be no more dependency on a certain order.

alter table xxx disable keys;

should work on MyISAM but will not work on InnoDB


What does "What user table" mean? If you drop all tables, they should be reinserted somewhere?


Also if we land #143 for this release, that needs to be taken into account as well.


@staabm: We need to support InnoDB as well

@jzaefferer: Typo, updated post :)


Dropped email and request columns from user table in a94f3d1

@Krinkle Krinkle referenced this issue from a commit
@Krinkle Krinkle Implement a basic command-line script class
- To be used for
 * issue #106 (generating a runToken)
 * issue #142 (performing the upgrade)
@Krinkle Krinkle was assigned
@Krinkle Krinkle referenced this issue from a commit
@Krinkle Krinkle Move swarmGetVersion into TestSwarmContext as getVersion
- Also added a way to bypass the cache for maintenance scripts,
  for issue #142.

- Renamed 1.0.0-pre to 1.0.0-alpha so that it works with
  version_compare. This also matches the guidelines of SemVer
  (updated README, )
@Krinkle Krinkle referenced this issue from a commit
@Krinkle Krinkle Add several methods to Database class
- Needed in the update script (issue #142)

- Moving around methods in a more logical order

- Added:

 * `tableExists`, `fieldInfo`, `fieldExists`
   Get info about the database. To be used in the update script.

 * `batchQueryFromFile`
   Given the contents of a (potentially large) .sql file, executes
   it in batches. Also strips out comments. Giving the contents
   to query() directly fails (tried it several times, it doesn't
   handle comments very well).

 * `addIdentifierQuotes`, `strEncode`
   wrapper around mysql_real_escape_string, but passing
   the current connection instead of falling back to the last opened
   connection. And also adding in a ping() so that escaping does
   not fail if the connection has gone to sleep in the mean time.

   Without this calls to mysql_real_escape_string could fail and
   should not be relied on always doing its thing (especially when
   called before the connection is opened, mysql_real_escape_string
   doesn't (and can't) do anything.

 * `ping`
   Wake up the connection or (re-)open it otherwise.

 * `freeResult`
   Wrapper for mysql_free_result, added call in getRows but not in
   other places. Afaik it can increase memory usage when called on
   a resource that was not fetched completely. So only use it on the
   resources where it is used for multiple rows and all rows have
   been fetched.

 * `ignoreErrors`
   When checking table existence, don't throw exceptions if the
   query returned an error.

- Lock system.

  If ./cache/database.lock exists, then Context won't create an
  instance of Database and throws an exception instead which
  index.php and api.php already handle well. This way pages won't
  look broken but are handled naturally (api.php will respond
  with a descriptive error in a valid response format and index.php
  will show a Error500Page).

- Misc.:
 * Added DerivativeWebRequest to init.php, forgotten in
   28b6595. Wasn't an issue since
   it is in the same file as WebRequest, so it is already loaded in
   most cases, but when a maintenance script uses
   DerivativeWebRequest directly it would fail.
@Krinkle Krinkle referenced this issue from a commit
@Krinkle Krinkle Create db update (issue #142) and db install script (issue #158)
- Implement method MaintenanceScript::cliInput
  Get an answer from the user from STDIN on the cli.
  This requires that the script be executed directly from shell as
  the primary command. If it detects a piped input, or writing output
  to a file, it will abort the script as soon as cliInput it used.

- Automatically output a line break if out() is used.
  In almost all cases this is the intention, cleaned up scripts
  that were making lots of calls like out(.. "\n").
  Added an outRaw() that circumvents this. In a few places in the
  upgrade script, output goes like "Foo..." and then "OK/FAILED"
  is appended to that line later on.

- Force a line break before a fatal script error() call output

- Moved SignupAction logic into a doCreateUser method so that it
  can be easily used by the upgrade script without having to either:
 * Duplicate seed/hashing logic
 * Create a fake request context, and then somehow undo the session
   manipulation (since SignupAction auto-logins)

- For now the update script only has '1.0.0-alpha' in it.
  It starts with 1 or 2 questions that can be skipped with --quick.
  These questions don't affect the actual update progress but safe
  overhead in the obvious case where there shouldn't be any updates.

- Actual updater method doesn't use versioning to update but looks
  at the actual database schema and executes updates based on what
  it should be and what it currently is. As a start it only contains
  updates for 0.2.0 -> 1.0.0-alpha. It is not a real updater as there
  are too many breaking changes in 1.0.0. Instead it asks the user
  for an additional confirmation to delete all data (except for user
  credentials and auth token), re-installs from testswarm.sql and
  then does several Signup actions and restores the seed/token

- Also implemented a simple database (re)install script that
  optionally wipes all data (as alternative for the old reset.sql)

  Easy for users that can't or don't want to use mysql tools.

  Can also be used as a bold way to upgrade to a new version if you
  don't care about old data.
@Krinkle Krinkle closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.