Commit graph

31 commits

Author SHA1 Message Date
Nurahmadie
7eb06fc0d5 Use NullString instead of checking for error. 2014-03-16 12:26:45 +07:00
Nurahmadie
44ffb70813 Use variadic parameters for DropColumns.
Also add some comments.
2014-03-16 12:26:18 +07:00
Nurahmadie
571f7d02b0 Fix some column type to work with both mysql and sqlite.
Basically this is caused by sqlite actually doesn't have any
column type restriction. also save gob type column as blob to enforce
byte-string value, since varchar with utf8 collation type will take at
least 3 byte to store, this will break YAML-Gob decoding at `params`
column.

Also fix some typo, and clean up fixtures code.
2014-03-15 18:20:11 +07:00
Nurahmadie
7cf4f2eb89 Preliminary MySQL support. Barely tested.
Requirements:
MySQL/MariaDB need to be configured with this settings:

  innodb_file_format = Barracuda
  innodb_file_per_table = On
  innodb_large_prefix = On

to support key prefix length up to 3042 bytes.

MySQL/MariaDB DSN will need this parameter:

  parseTime=true

as per [1]

The migration system itself mostly inspired by Rails (ActiveRecord),
but it still rough at the edges. Could use some inputs.

Next Todo: more testing!

[1]  https://github.com/go-sql-driver/mysql#parsetime
2014-03-14 02:28:10 +07:00
Nurahmadie
5903eb8f04 Add wrapper for common column types for easier column type
transformation between databases.
2014-03-13 18:53:52 +07:00
Nurahmadie
97825cf6bf Add usage info at migration script generator.
Also suppress error at the latest migration script
for backward compatibility with existing database, in which
open_invitations column wasn't added via migration.
2014-03-12 08:33:04 +07:00
Nurahmadie
89a00bd448 Refactor tests, add test for ChangeColumn method. 2014-03-12 07:04:34 +07:00
Nurahmadie
92dfcbfca9 Move database schema to migration script. 2014-03-10 20:28:04 +07:00
Nurahmadie
76ed21c40f Cleanup some leftover
Don't have to import mattn/go-sqlite3 at pkg/database/migrate/sqlite.go
Remove unused DriverFunction declaration at migrate.go
2014-03-10 11:30:39 +07:00
Nurahmadie
d61bb3ef6c Fix index operation tests 2014-03-10 07:17:47 +07:00
Nurahmadie
489e38908a Implement ChangeColumn, AddIndex, and DropIndex methods for Operation interface. 2014-03-10 07:11:15 +07:00
Nurahmadie
81cf496811 Refactor migration.
Add `ChangeColumn`, `AddIndex`, `DropIndex` method to
Operation interface.
2014-03-10 07:08:58 +07:00
Nurahmadie
51519b62dd Actually use --driver option to set database driver for drone.
This includes refactoring database setup, and migration system.

Remove setupDatabase from main and use `Init` method from database
package.

At database package, defines Init method which actually initiate
database with options given from comand line flag. I think `--path`
wont be used anywhere so I plan to remove it later.

Both meddler and migration initiated here, then we call `Set` method
to setup all the tables, etc. Here I think I want to separate database
schema and turn it into migration script instead, later maybe.

At migration package I made some tweak to `Operation` interface.
Realized that it's ludicrous to let migration driver re-implement `Exec`
and `Query`, I made migration script to receive The whole
migrationDriver struct which contains both Operation implementor, and
the Tx itself. This made possible thanks to Go struct being able to
promote its member, now our migration is more transparent.

There's also stub implementation for bot mysql and postgresql, will
implement this really soon.
2014-03-08 12:19:28 +07:00
Nurahmadie
d9e4f3f509 Add shell script to generate migration script. 2014-02-19 08:15:51 +07:00
Nurahmadie
7b4c698e79 Refactor columns matching method 2014-02-19 07:38:53 +07:00
Nurahmadie
21f7fcb853 Fix index operations:
- Pass args as variadic params
- Tests for index operations
- Refactor fetchColumns
2014-02-19 01:11:41 +07:00
Nurahmadie
8d7cf16a89 Add func to fetch SQL definition for indices.
Also rearrange sql.Result and err declaration.
2014-02-18 21:22:22 +07:00
Nurahmadie
7a75c2d004 Keep indices when dropping/renaming columns. 2014-02-18 18:32:04 +07:00
Brad Rydzewski
a200c7a0a2 altered migration to set default github domain and url 2014-02-17 23:08:06 -07:00
Brad Rydzewski
cb042e1c1a fixed compile error in migration script 2014-02-17 22:48:31 -07:00
Brad Rydzewski
bbb4bf48e0 Merge remote-tracking branch 'origin/master' 2014-02-17 22:42:01 -07:00
Brad Rydzewski
0e83e76ef4 removed unused migration sample file 2014-02-17 22:41:56 -07:00
Brad Rydzewski
85e60e4ee2 Merge pull request #75 from floatdrop/github-enterprise-support
GitHub Enterprise Support
2014-02-17 21:38:28 -08:00
Vsevolod Strukchinsky
1505175288 Migration file based on #83
I choosed Rev3, because Rev2 will be about "open invitations" feature.
2014-02-16 11:57:16 +06:00
Nurahmadie
4ef0f1b437 Integrate migrations with drone.
Also add migration to tests.
2014-02-16 03:47:30 +07:00
Nurahmadie
da8d4346ee Add tests to migrate existing database without migration attributes. 2014-02-16 02:23:26 +07:00
Nurahmadie
8ce87f0d2c More tests for alter columns migration
Also change the way we handle columns rename migration.
SQLite restrict column addition not to have PRIMARY KEY and/or
UNIQUE attribute, so we have to change from:

add new column -> migrate data from old column to new column ->
rename old table -> create new table with old columns removed ->
migrate data from old table to the new table -> drop old table

to directly:
rename old table -> create new table with renamed columns ->
migrate data from old table to the new table -> drop old table
2014-02-16 00:56:17 +07:00
Nurahmadie
4465b2654d Fix migration step not checked against current version.
Add tests for DropColumns.
2014-02-15 22:17:22 +07:00
Nurahmadie
54a9544044 Integrate MigrationDriver to migrate.go 2014-02-15 20:16:54 +07:00
Nurahmadie
d2eed594ea Migration Driver for SQLite
Need more tests.
2014-02-15 19:29:53 +07:00
Brad Rydzewski
8d135d7b22 package for database migrations 2014-02-10 03:03:22 -07:00