This commit is contained in:
		
							parent
							
								
									53785b6e6e
								
							
						
					
					
						commit
						a4de16a1dd
					
				| @ -11,6 +11,7 @@ jobs: | ||||
|       env: | ||||
|         GOPATH: /go-cache-volume | ||||
|         GOCACHE: /go-cache-volume/build-cache | ||||
|         GOLANGCI_LINT_CACHE: /go-cache-volume/golangci-lint | ||||
|     steps: | ||||
|       - name: checkout | ||||
|         env: | ||||
|  | ||||
| @ -11,8 +11,8 @@ import ( | ||||
| ) | ||||
| 
 | ||||
| var ( | ||||
| 	// Tracks whether the DB connector has been initialized | ||||
| 	is_initialized bool | ||||
| 	// // Tracks whether the DB connector has been initialized | ||||
| 	// is_initialized bool | ||||
| 
 | ||||
| 	// The SQL schema of the database under management | ||||
| 	sql_schema *string | ||||
| @ -44,7 +44,7 @@ func Init(schema *string, migrationsList *[]string) { | ||||
| 	sql_schema = schema | ||||
| 	migrations = migrationsList | ||||
| 	version_number = uint(len(*migrations)) | ||||
| 	is_initialized = true | ||||
| 	// is_initialized = true | ||||
| } | ||||
| 
 | ||||
| func Create(path string) (*sqlx.DB, error) { | ||||
| @ -93,7 +93,7 @@ func CheckAndUpdateVersion(db *sqlx.DB) error { | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| // Run all the migrations from version X to version Y, and update the `database_version` table's `version_number` | ||||
| // UpgradeFromXToY runs all the migrations from version X to version Y, and update the `database_version` table's `version_number` | ||||
| func UpgradeFromXToY(db *sqlx.DB, x uint, y uint) { | ||||
| 	for i := x; i < y; i++ { | ||||
| 		fmt.Print(ColorCyan) | ||||
|  | ||||
| @ -51,12 +51,12 @@ func TestVersionUpgrade(t *testing.T) { | ||||
| 
 | ||||
| 	get_version := func(c *sqlx.DB) (ret int) { | ||||
| 		// TODO: this should be a function exposed by the `db` package itself | ||||
| 		c.Get(&ret, "select version from db_version") | ||||
| 		require.NoError(c.Get(&ret, "select version from db_version")) | ||||
| 		return | ||||
| 	} | ||||
| 
 | ||||
| 	var items []int | ||||
| 	connection.Select(&items, "select * from items") | ||||
| 	require.NoError(connection.Select(&items, "select * from items")) | ||||
| 	require.Len(items, 0) | ||||
| 	require.Equal(0, get_version(connection)) | ||||
| 
 | ||||
| @ -66,7 +66,7 @@ func TestVersionUpgrade(t *testing.T) { | ||||
| 	db.UpgradeFromXToY(connection, uint(len(migrations)-1), uint(len(migrations))) | ||||
| 
 | ||||
| 	var items2 []int | ||||
| 	connection.Select(&items2, "select * from items") | ||||
| 	require.NoError(connection.Select(&items2, "select * from items")) | ||||
| 	require.Len(items2, 1) | ||||
| 	require.Equal(1, get_version(connection)) | ||||
| 
 | ||||
| @ -79,7 +79,7 @@ func TestVersionUpgrade(t *testing.T) { | ||||
| 		ID   uint64 `db:"rowid"` | ||||
| 		Name string `db:"name"` | ||||
| 	} | ||||
| 	connection.Select(&items3, "select * from items") | ||||
| 	require.NoError(connection.Select(&items3, "select * from items")) | ||||
| 	require.Len(items2, 1) | ||||
| 	assert.Equal(t, "asdf", items3[0].Name) | ||||
| 	require.Equal(2, get_version(connection)) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user