Restore a SQL dump
masterThe output is a plain SQL file. You can restore it using standard CLI tools like psql, mysql, or sqlite3. To restore via Ruby/ActiveRecord, use:
ActiveRecord::Base.connection.execute(File.read('path/to/new_dump.sql'))Important Tips:
- Reset Sequences: After restoration, reset primary key sequences to ensure new seeds work correctly:
ActiveRecord::Base.connection.tables.each do |table| ActiveRecord::Base.connection.reset_pk_sequence!(table) end - PostgreSQL Circular Dependencies: If you encounter circular dependencies in PostgreSQL, you may need to make foreign keys
NOT DEFERRABLEbefore restoration and useSET CONSTRAINTS ALL DEFERREDwithin a transaction during the load.
# Restore via Ruby
ActiveRecord::Base.connection.execute(File.read('path/to/new_dump.sql'))