table-init

command
v0.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 11, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

Table Init

table-init is a Go-based utility designed to initialize and migrate database tables using GORM. This tool retrieves configuration from environment variables and performs database migrations to ensure the schema is up-to-date.

The application is designed to be run as a standalone utility or as part of a CI/CD pipeline to ensure that the database schema is consistent across environments.

The database this is designed to work with is Postgres.

Features

  • Retrieves database configuration from environment variables.
  • Connects to the database using a configurable connector.
  • Performs automatic migrations for specified models.

Configuration

The application uses the following environment variables for configuration:

  • DB_HOST: Database host (default: localhost)
  • DB_PORT: Database port (default: 5432)
  • DB_USER: Database user (default: test_user)
  • DB_PASSWORD: Database password (default: test_password)
  • DB_NAME: Database name (default: test_db)
  • INSTANCE_CONNECTION_NAME: Instance connection name (optional)

Usage

To run the application, execute the following command:

go run cmd/table-init/main.go

Code Overview

Main Function

The main function initializes the context and configuration, then calls the run function to perform the database connection and migration.

startLine: 32
endLine: 39

Testing

The project includes unit tests to verify the functionality of environment variable retrieval, configuration, and the run function.

To run the tests, use the following command:

go test ./...

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL