github.com/shoshinnikita/budget-manager@v0.7.1-0.20220131195411-8c46ff1c6778/internal/db/pg/migrations/1_init.go (about)

     1  package migrations
     2  
     3  import (
     4  	"database/sql"
     5  )
     6  
     7  func initMigration(tx *sql.Tx) error {
     8  	_, err := tx.Exec(`
     9  		CREATE TABLE IF NOT EXISTS months (
    10  			id bigserial PRIMARY KEY,
    11  		
    12  			year  bigint,
    13  			month bigint,
    14  		
    15  			daily_budget bigint,
    16  			total_income bigint,
    17  			total_spend  bigint,
    18  			result       bigint
    19  		);
    20  
    21  		CREATE TABLE IF NOT EXISTS days (
    22  			id bigserial PRIMARY KEY,
    23  		
    24  			month_id bigint,
    25  		
    26  			day   bigint,
    27  			saldo bigint
    28  		);
    29  
    30  		CREATE TABLE IF NOT EXISTS incomes (
    31  			id bigserial PRIMARY KEY,
    32  		
    33  			month_id bigint,
    34  		
    35  			title  text,
    36  			notes  text,
    37  			income bigint
    38  		);
    39  
    40  		CREATE TABLE IF NOT EXISTS monthly_payments (
    41  			id bigserial PRIMARY KEY,
    42  		
    43  			month_id bigint,
    44  		
    45  			title    text,
    46  			type_id  bigint,
    47  			notes    text,
    48  			cost     bigint
    49  		);
    50  
    51  		CREATE TABLE IF NOT EXISTS spends (
    52  			id bigserial PRIMARY KEY,
    53  		
    54  			day_id bigint,
    55  		
    56  			title   text,
    57  			type_id bigint,
    58  			notes   text,
    59  			cost    bigint
    60  		);
    61  
    62  		CREATE TABLE IF NOT EXISTS spend_types (
    63  			id   bigserial PRIMARY KEY,
    64  			name text
    65  		);`,
    66  	)
    67  	return err
    68  }