202407012100_transactions.go raw

   1  package migrations
   2  
   3  import (
   4  	_ "embed"
   5  	"text/template"
   6  
   7  	"github.com/go-gormigrate/gormigrate/v2"
   8  	"gorm.io/gorm"
   9  )
  10  
  11  const transactionsMigration = `
  12  CREATE TABLE transactions(
  13  	id {{ .AutoincrementPrimaryKey }},
  14  	app_id integer,
  15  	request_event_id integer,
  16  	type text,
  17  	state text,
  18  	payment_request text,
  19  	preimage text,
  20  	payment_hash text,
  21  	description text,
  22  	description_hash text,
  23  	amount_msat integer,
  24  	fee_msat integer,
  25  	fee_reserve_msat integer,
  26  	created_at {{ .Timestamp }},
  27  	updated_at {{ .Timestamp }},
  28  	expires_at {{ .Timestamp }},
  29  	settled_at {{ .Timestamp }},
  30  	metadata text,
  31  	self_payment boolean
  32  );
  33  
  34  DROP TABLE payments;
  35  
  36  ALTER TABLE apps ADD isolated boolean;
  37  UPDATE apps set isolated = false;
  38  
  39  ALTER TABLE app_permissions RENAME COLUMN max_amount TO max_amount_sat;
  40  `
  41  
  42  var transactionsMigrationTmpl = template.Must(template.New("transactionsMigration").Parse(transactionsMigration))
  43  
  44  // This migration
  45  // - Replaces the old payments table with a new transactions table
  46  // - Adds new properties to apps
  47  //   - isolated boolean
  48  //
  49  // - Renames max amount on app permissions to be clear its in sats
  50  var _202407012100_transactions = &gormigrate.Migration{
  51  	ID: "202407012100_transactions",
  52  	Migrate: func(tx *gorm.DB) error {
  53  
  54  		if err := exec(tx, transactionsMigrationTmpl); err != nil {
  55  			return err
  56  		}
  57  
  58  		return nil
  59  	},
  60  	Rollback: func(tx *gorm.DB) error {
  61  		return nil
  62  	},
  63  }
  64