Skip to content

Commit

Permalink
Merge pull request #2 from cjlapao/initial-commit
Browse files Browse the repository at this point in the history
moved the migrations to a different namespace
  • Loading branch information
cjlapao committed Nov 19, 2022
2 parents 7726829 + 87a43e1 commit f710234
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
8 changes: 0 additions & 8 deletions db_migrations/adapters.go

This file was deleted.

9 changes: 8 additions & 1 deletion db_migrations/repository.go → migrations/adapters.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
package db_migrations
package migrations

type Migration interface {
Name() string
Order() int
Up() bool
Down() bool
}

type MigrationsRepository interface {
CreateTable() error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package db_migrations
package migrations

import "time"

Expand Down
2 changes: 1 addition & 1 deletion db_migrations/main.go → migrations/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package db_migrations
package migrations

import (
"context"
Expand Down
18 changes: 9 additions & 9 deletions sql/sql_migration_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"fmt"

"github.com/cjlapao/common-go-database/db_migrations"
"github.com/cjlapao/common-go-database/migrations"
"github.com/cjlapao/common-go/log"
"github.com/google/uuid"
)
Expand Down Expand Up @@ -36,7 +36,7 @@ func (m *SqlMigrationsRepo) CreateTable() error {
defer globalDb.Close()

_, err := globalDb.ExecContext(`
CREATE TABLE IF NOT EXISTS ` + db_migrations.MIGRATION_TABLE_NAME + `(
CREATE TABLE IF NOT EXISTS ` + migrations.MIGRATION_TABLE_NAME + `(
id CHAR(36) NOT NULL PRIMARY KEY COMMENT 'Primary Key',
executed_on DATETIME COMMENT 'Time of execution',
name CHAR(150) NOT NULL COMMENT 'Migration Name',
Expand All @@ -53,8 +53,8 @@ func (m *SqlMigrationsRepo) CreateTable() error {
return nil
}

func (m *SqlMigrationsRepo) GetAppliedMigrations() ([]db_migrations.MigrationEntity, error) {
var queryResult []db_migrations.MigrationEntity
func (m *SqlMigrationsRepo) GetAppliedMigrations() ([]migrations.MigrationEntity, error) {
var queryResult []migrations.MigrationEntity
globalDb := m.database.Connect()

defer globalDb.Close()
Expand All @@ -63,7 +63,7 @@ func (m *SqlMigrationsRepo) GetAppliedMigrations() ([]db_migrations.MigrationEnt
SELECT
*
FROM
` + db_migrations.MIGRATION_TABLE_NAME + `
` + migrations.MIGRATION_TABLE_NAME + `
WHERE
status = TRUE
ORDER BY
Expand All @@ -74,10 +74,10 @@ ORDER BY
return nil, err
}

queryResult = make([]db_migrations.MigrationEntity, 0)
queryResult = make([]migrations.MigrationEntity, 0)

for result.Next() {
var migration db_migrations.MigrationEntity
var migration migrations.MigrationEntity

err := result.Scan(&migration.ID, &migration.ExecutedOn, &migration.Name, &migration.Status)

Expand All @@ -90,7 +90,7 @@ ORDER BY
return queryResult, nil
}

func (m *SqlMigrationsRepo) SaveMigrationStatus(migration db_migrations.MigrationEntity) error {
func (m *SqlMigrationsRepo) SaveMigrationStatus(migration migrations.MigrationEntity) error {
globalDb := m.database.Connect()

migration.ID = uuid.NewString()
Expand All @@ -99,7 +99,7 @@ func (m *SqlMigrationsRepo) SaveMigrationStatus(migration db_migrations.Migratio

_, err := globalDb.QueryContext(`
INSERT INTO
`+db_migrations.MIGRATION_TABLE_NAME+`(id, executed_on, name, status)
`+migrations.MIGRATION_TABLE_NAME+`(id, executed_on, name, status)
VALUES(?, ?, ?, ?)
`,
migration.ID,
Expand Down

0 comments on commit f710234

Please sign in to comment.