Menu

What Is Rails' structure.sql? What's It For?
📰

What Is Rails' structure.sql? What's It For?

DEV Community: rails·Kaziu·about 6 hours ago
#36TFCHq1
#devtorails#devto#dev#structure#migrations
Reading 0:00
15s threshold

When you work on a Rails project, you'll come across a huge file called db/structure.sql .

"What is this? It changes on its own, so am I allowed to touch it?" It's an easy file to be confused by, so here's a beginner-friendly rundown.

Bottom line: the DB's "finished blueprint"

In a nutshell, structure.sql is

a "finished blueprint (snapshot)" that bundles the SQL statements needed to recreate the current database structure entirely from scratch

What's more, it's a file that Rails generates and updates automatically ; it's not something people write by hand.

Here's roughly what's inside:

CREATE TABLE `deals` ( -- Statement that creates the "deals" table `id` bigint unsigned NOT NULL , `name` varchar ( 255 ) , . . . ) ;

CREATE TABLE `contacts` ( . . . ) ; -- Statement that creates the "contacts" table . . . ( continues for every table ) . . .

-- At the end, a ledger of "which schema changes have been applied so far" INSERT INTO `schema_migrations` VALUES ( '20260806000000' ) , ( '20260805000000' ) , .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.