Import a Rails schema.rb
Dette indhold er ikke tilgængeligt i dit sprog endnu.
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.
The file
Section titled “The file”db/schema.rbIf your project uses config.active_record.schema_format = :sql, you have
db/structure.sql instead — import that as
SQL DDL.
Detection
Section titled “Detection”Adminium detects Rails by ActiveRecord::Schema or create_table calls.
What is read
Section titled “What is read”| 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 |
Rails conventions Adminium follows
Section titled “Rails conventions Adminium follows”idis the primary key, implicit unlessid: falseorprimary_key: "uuid".created_at/updated_at(t.timestamps) are recognized as system-managed and default to read-only in forms — you do not hand-editupdated_at.t.references :usercreatesuser_idplus a foreign key whenforeign_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 foradd_foreign_keylines at the bottom.
Polymorphic associations do not import as relations
Section titled “Polymorphic associations do not import as relations”t.references :commentable, polymorphic: trueThat 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.
Single-table inheritance
Section titled “Single-table inheritance”type plus the union of every subclass’s columns is exactly what the database
holds, and exactly what Adminium imports.
- Enums. Rails
enumlives in the model, not inschema.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.