refactor: déplacer schema vers sql/schema.sql et sql.Schema()
This commit is contained in:
parent
e945907771
commit
40dcd82e54
5 changed files with 20 additions and 10 deletions
|
@ -11,6 +11,7 @@ ADD data/ data/
|
|||
ADD handlers/ handlers/
|
||||
ADD models/ models/
|
||||
ADD responses/ responses/
|
||||
ADD sql/ sql/
|
||||
ADD web/ web/
|
||||
|
||||
RUN CGO_ENABLED=0 go build -a -o bottin-agenda .
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"git.agecem.com/agecem/bottin-agenda/models"
|
||||
"git.agecem.com/agecem/bottin-agenda/sql"
|
||||
_ "github.com/jackc/pgx/stdlib"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/spf13/viper"
|
||||
|
@ -59,7 +60,7 @@ func NewDataClient(connection PostgresConnection) (*DataClient, error) {
|
|||
}
|
||||
|
||||
func (d *DataClient) Seed() (int64, error) {
|
||||
result, err := d.DB.Exec(models.Schema)
|
||||
result, err := d.DB.Exec(sql.Schema())
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
|
|
@ -2,15 +2,6 @@ package models
|
|||
|
||||
import "time"
|
||||
|
||||
var Schema = `
|
||||
CREATE TABLE IF NOT EXISTS transactions (
|
||||
id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
|
||||
membre_id VARCHAR(7),
|
||||
given_at TIMESTAMP,
|
||||
is_perpetual BOOLEAN
|
||||
);
|
||||
`
|
||||
|
||||
type Transaction struct {
|
||||
ID string `db:"id" json:"id"`
|
||||
MembreID string `db:"membre_id" json:"membre_id"`
|
||||
|
|
7
sql/schema.sql
Normal file
7
sql/schema.sql
Normal file
|
@ -0,0 +1,7 @@
|
|||
-- Schema
|
||||
CREATE TABLE IF NOT EXISTS transactions (
|
||||
id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
|
||||
membre_id VARCHAR(7) NOT NULL,
|
||||
given_at TIMESTAMP DEFAULT current_timestamp,
|
||||
is_perpetual BOOLEAN NOT NULL
|
||||
);
|
10
sql/sql.go
Normal file
10
sql/sql.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package sql
|
||||
|
||||
import _ "embed"
|
||||
|
||||
//go:embed schema.sql
|
||||
var schema string
|
||||
|
||||
func Schema() string {
|
||||
return schema
|
||||
}
|
Loading…
Reference in a new issue