-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
704a8a6
commit 10c9494
Showing
11 changed files
with
150 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ services: | |
networks: | ||
- backend | ||
|
||
|
||
postgres: | ||
image: bitnami/postgresql | ||
container_name: mydb_container | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package cassandra | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
|
||
"github.com/gocql/gocql" | ||
"github.com/golang-migrate/migrate/v4" | ||
_ "github.com/golang-migrate/migrate/v4/source/file" | ||
"github.com/golang-migrate/migrate/v4/database/cassandra" | ||
"github.com/rs/zerolog" | ||
) | ||
|
||
// RunMigrations applies Cassandra migrations from a directory | ||
func Migrate(session *gocql.Session, logger zerolog.Logger, migrationPath string, KeySpaceName string) error { | ||
// Convert migration path to absolute path | ||
absPath, err := filepath.Abs(migrationPath) | ||
if err != nil { | ||
logger.Error().Err(err).Msg("Failed to resolve migration path") | ||
return fmt.Errorf("failed to resolve migration path: %w", err) | ||
} | ||
|
||
// Initialize Cassandra migration driver | ||
driver, err := cassandra.WithInstance(session, &cassandra.Config{ | ||
KeyspaceName : KeySpaceName, | ||
}) | ||
if err != nil { | ||
logger.Error().Err(err).Msg("Failed to create Cassandra migration driver") | ||
return fmt.Errorf("failed to create Cassandra driver: %w", err) | ||
} | ||
|
||
// Initialize the migrate instance with file source | ||
m, err := migrate.NewWithDatabaseInstance(fmt.Sprintf("file://%s", absPath), "cassandra", driver) | ||
if err != nil { | ||
logger.Error().Err(err).Msg("Failed to initialize migrations") | ||
return fmt.Errorf("failed to initialize migrations: %w", err) | ||
} | ||
|
||
// Apply migrations | ||
err = m.Up() | ||
if err != nil && err != migrate.ErrNoChange { | ||
logger.Error().Err(err).Msg("Migration failed") | ||
return fmt.Errorf("migration failed: %w", err) | ||
} | ||
|
||
if err == migrate.ErrNoChange { | ||
logger.Info().Msg("No new Cassandra migrations to apply") | ||
return nil | ||
} | ||
|
||
logger.Info().Msg("Cassandra migrations applied successfully!") | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS orders; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
CREATE TABLE IF NOT EXISTS orders ( | ||
id UUID PRIMARY KEY, | ||
user_id UUID, | ||
total DECIMAL | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters