Skip to content

Import a Rails schema.rb

db/schema.rb is the best-behaved ORM import format, because it is not a description of your models — it is Rails’ dump of the actual database, regenerated by every migration. It is already a snapshot.

db/schema.rb

If your project uses config.active_record.schema_format = :sql, you have db/structure.sql instead — import that as SQL DDL.

Adminium detects Rails by ActiveRecord::Schema or create_table calls.

schema.rb Becomes
create_table "users" table
t.string, t.integer, t.datetime, … columns
The implicit id primary key
add_foreign_key foreign key + relation
t.references / t.belongs_to foreign key column
add_index, t.index index
unique: true unique constraint
null: false non-nullable
default: default
limit:, precision:, scale: type refinements
  • id is the primary key, implicit unless id: false or primary_key: "uuid".
  • created_at / updated_at (t.timestamps) are recognized as system-managed and default to read-only in forms — you do not hand-edit updated_at.
  • t.references :user creates user_id plus a foreign key when foreign_key: true. Without it, Rails creates the column and no constraint — so Adminium sees an integer column, not a relation. This is common in older schemas. Check for add_foreign_key lines at the bottom.

Polymorphic associations do not import as relations

Section titled “Polymorphic associations do not import as relations”
t.references :commentable, polymorphic: true

That is two columns — commentable_id and commentable_type — and no foreign key, because it cannot have one: the target table is a runtime value. Adminium imports both columns and no relation. Nothing is lost that the database ever knew.

type plus the union of every subclass’s columns is exactly what the database holds, and exactly what Adminium imports.

  • Enums. Rails enum lives in the model, not in schema.rb, and is usually backed by an integer or string column. Adminium imports the underlying column. Add an enum override to get a select input with your labels.
  • The version line (define(version: 2024_01_15_120000)) is the migration timestamp — useful for knowing how current your dump is.