The schema definition that the schema file is written in. The generated db/schema.lua calls ActiveRecord.Schema:define with the version of the schema and a function whose schema statements create every table, index and foreign key. Loading the file, with flux db:schema:load or when the server starts with an empty database, builds the whole database at once and records the migrations up to that version as run. Schema files that define a 'Structure' object with a create_tables method are recognized, but they cannot be loaded.

Summary

Functions

load(info, callback)shared internal
Runs the statements of a schema definition and records the migrations up to its version as run.

Methods

Creates all tables of the schema.
Defines the schema of the database.
Creates a schema object.

Functions

ActiveRecord.Schema.load(info, callback)

shared internal packages/active_record/lib/migrator/schema.lua:57

Internal

This function is internal. It is not part of the public API and may change without notice.

Runs the statements of a schema definition and records the migrations up to its version as run.

Parameters

  • info Map version
  • callback Function

Methods

ActiveRecord.Schema:create_tables()

shared packages/active_record/lib/migrator/schema.lua:48

Creates all tables of the schema. Does nothing; the schema files that hold a 'Structure' object override it.

Returns

  • ActiveRecord::Schema(self)

ActiveRecord.Schema:define(info, callback)

shared packages/active_record/lib/migrator/schema.lua:37

Defines the schema of the database. Used by the generated 'db/schema.lua' file, which is loaded with flux db:schema:load or when a fresh database is set up. The statements of the callback are run right away, after which the given version and every older migration are recorded as run.

ActiveRecord.Schema:define({ version = 20190309120000 }, function()
  create_table('users', { force = true }, function(t)
    t:string { 'steam_id', null = false }
    t:timestamps()
  end)

  add_index('users', { 'steam_id' }, { name = 'users_steam_id_index' })
end)

Called with a version alone, as the schema files that hold a 'Structure' object do, it returns a schema object instead and runs nothing.

Parameters

  • info Map/Number/String a table with the version, or the version itself
  • callback Function optional, defaults to nil makes the schema statements

Returns

  • ActiveRecord::Schema only for the one-argument form

ActiveRecord.Schema:init(version)

shared packages/active_record/lib/migrator/schema.lua:14

Creates a schema object. Only used by schema files that hold a 'Structure' object with a #create_tables method.

Parameters

  • version Number/String schema version

Defined in