github.com/nafhul/migrate@v3.5.4+incompatible/migration_test.go (about)

     1  package migrate
     2  
     3  import (
     4  	"fmt"
     5  	"io/ioutil"
     6  	"log"
     7  	"strings"
     8  )
     9  
    10  func ExampleNewMigration() {
    11  	// Create a dummy migration body, this is coming from the source usually.
    12  	body := ioutil.NopCloser(strings.NewReader("dumy migration that creates users table"))
    13  
    14  	// Create a new Migration that represents version 1486686016.
    15  	// Once this migration has been applied to the database, the new
    16  	// migration version will be 1486689359.
    17  	migr, err := NewMigration(body, "create_users_table", 1486686016, 1486689359)
    18  	if err != nil {
    19  		log.Fatal(err)
    20  	}
    21  
    22  	fmt.Print(migr.LogString())
    23  	// Output:
    24  	// 1486686016/u create_users_table
    25  }
    26  
    27  func ExampleNewMigration_nilMigration() {
    28  	// Create a new Migration that represents a NilMigration.
    29  	// Once this migration has been applied to the database, the new
    30  	// migration version will be 1486689359.
    31  	migr, err := NewMigration(nil, "", 1486686016, 1486689359)
    32  	if err != nil {
    33  		log.Fatal(err)
    34  	}
    35  
    36  	fmt.Print(migr.LogString())
    37  	// Output:
    38  	// 1486686016/u <empty>
    39  }
    40  
    41  func ExampleNewMigration_nilVersion() {
    42  	// Create a dummy migration body, this is coming from the source usually.
    43  	body := ioutil.NopCloser(strings.NewReader("dumy migration that deletes users table"))
    44  
    45  	// Create a new Migration that represents version 1486686016.
    46  	// This is the last available down migration, so the migration version
    47  	// will be -1, meaning NilVersion once this migration ran.
    48  	migr, err := NewMigration(body, "drop_users_table", 1486686016, -1)
    49  	if err != nil {
    50  		log.Fatal(err)
    51  	}
    52  
    53  	fmt.Print(migr.LogString())
    54  	// Output:
    55  	// 1486686016/d drop_users_table
    56  }