schema

package
v6.1.6 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DumpCmd = &cobra.Command{
	Use:   "dump",
	Short: "Dumps out the schema of the selected database",
	RunE: func(cmd *cobra.Command, args []string) error {
		env := cmd.Flag("env")
		if env == nil {
			return errors.New("env is required")
		}
		dumpOptions.env = env.Value.String()
		c, err := pop.Connect(dumpOptions.env)
		if err != nil {
			return err
		}
		var out io.Writer
		rollback := func() {}
		if dumpOptions.output == "-" {
			out = os.Stdout
		} else {
			err = os.MkdirAll(filepath.Dir(dumpOptions.output), 0755)
			if err != nil {
				return err
			}
			out, err = os.Create(dumpOptions.output)
			if err != nil {
				return err
			}
			rollback = func() {
				os.RemoveAll(dumpOptions.output)
			}
		}
		if err := c.Dialect.DumpSchema(out); err != nil {
			rollback()
			return err
		}
		return nil
	},
}

DumpCmd dumps out the schema of the selected database.

View Source
var LoadCmd = &cobra.Command{
	Use:   "load",
	Short: "Load a schema.sql file into a database",
	RunE: func(cmd *cobra.Command, args []string) error {
		env := cmd.Flag("env")
		if env == nil {
			return errors.New("env is required")
		}
		loadOptions.env = env.Value.String()

		f, err := os.Open(loadOptions.input)
		if err != nil {
			return fmt.Errorf("unable to load schema file: %w", err)
		}
		defer f.Close()

		c, err := pop.Connect(loadOptions.env)
		if err != nil {
			return fmt.Errorf("unable to connect to database: %w", err)
		}
		defer c.Close()

		return c.Dialect.LoadSchema(f)
	},
}

LoadCmd loads a schema.sql file into a database.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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