console

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package console is the one command the notifications component ships.

NotificationTableCommand writes the migration that creates the table notifications.TableStore reads. It writes a file and runs nothing: a migration that ran itself would be N replicas racing each other at boot, and emitting a file is what lets somebody read it before it reaches production.

The SQL it writes is notifications.Migrations, not a stub file of its own, so there is no file to locate and no install layout to depend on. A project that keeps its migrations as Go values hands that to the migrator and never runs this command; a project that keeps .sql files runs it. Either way there is one definition of the table.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NotificationTableCommand

type NotificationTableCommand struct {
	// Directory is where the migration is written. Empty means the working
	// directory's database/migrations, which is where the rest of them live.
	Directory string

	// Now returns the timestamp the file is named with. Nil means the process
	// clock, and a test passes a fixed one.
	Now func() time.Time
}

NotificationTableCommand writes the migration that creates the notifications table.

It answers to `make:notifications-table`, and to that name only: two names for one command is two things to keep in step.

It writes a file and runs nothing. A migration that ran itself would be N replicas racing each other at boot, and emitting a file is what lets somebody read it before it reaches production.

A project that keeps its migrations as Go values hands notifications.Migrations to the migrator instead and never runs this. The two do not diverge: the SQL this writes is read off that.

func NewNotificationTableCommand

func NewNotificationTableCommand(directory string) *NotificationTableCommand

NewNotificationTableCommand returns the command, writing into directory. An empty directory means database/migrations under the working directory.

func (*NotificationTableCommand) Command

Command is the registry entry for make:notifications-table.

A command is registered rather than discovered by scanning: one missing from the registry does not exist, and one in it with a broken Run does not build.

func (*NotificationTableCommand) Handle

Handle writes the migration.

An existing migration is an error rather than an overwrite, because the one that is there may already have run somewhere.

func (*NotificationTableCommand) MigrationExists

func (c *NotificationTableCommand) MigrationExists() (bool, error)

MigrationExists reports whether a migration for the table is already there.

The glob is on the suffix, so a migration written yesterday under a different timestamp still counts.

func (*NotificationTableCommand) MigrationName

func (c *NotificationTableCommand) MigrationName() string

MigrationName is the file the migration is written as. It is stamped with the time so migrations sort in the order they were created, which is the order they have to run in.

func (*NotificationTableCommand) MigrationStub

func (c *NotificationTableCommand) MigrationStub() (string, error)

MigrationStub is the SQL the migration is written with.

It is read off notifications.Migrations rather than a stub file of its own, so the table this writes and the table a Go migration creates cannot drift. The statements come back from migrations.UpStatements, which runs the migration against a connection that records rather than executes, so nothing here reaches a server.

func (*NotificationTableCommand) MigrationTableName

func (c *NotificationTableCommand) MigrationTableName() string

MigrationTableName is the table the migration creates. It is exported because the name is what a caller checks a generated file against.

Jump to

Keyboard shortcuts

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