Installing Eloquent Driver0:00
Cedamic's entire data layer is driver based. That flat file mode, that's just the default driver that we ship with, because we love it and feel like it's perfect for most sites. If you want to use a database, we have an Eloquent driver that can do that for you in just a matter of minutes. So let's take the site we've already built and move it into a database, step by step. Here's our Eloquent driver package. So we're going to install this with Composer. Let's go to our command line, install this package. While that's going, I'm going to grab this command, we're going to publish the config.
Updating Driver Configuration0:59
knows about it. We store indexes of these IDs, so we can build up our flat file API and do all the cool magic stuff that static does. The next step is in the Eloquent driver, we're going to change model to static eloquent entries, UUID entry model. So let's do that. Let's go to config, static eloquent driver, and then go ahead and update that. Next we're going to publish our migrations. So let's do that. We're going to make this change, which will allow us to use string IDs.
Running Database Migrations1:30
So let's do that. We're going to make this change, which will allow us to use string IDs. And then we're going to run php artisan migrate. Before we do that, let's make sure we have our database configured properly. All right, we'll use LaraSmash as the database. And I've set that empty one up in MySQL and SQL ACE. And we're ready to run the migration. Let's take a look at our database. And now we have all of the tables that we're going to need. We just don't have any content yet.
Importing Content to DB2:07
And now we have all of the tables that we're going to need. We just don't have any content yet. So let's import all of our content. So there are important methods for each repository type assets, blueprints, collections, etc. We recommend running these one at a time instead of in bulk so that you can see if there's any errors or any issues that you might need to take a look at. Let's run through these real quick. All right, all of our content is imported. Let's take a look at the database one more time. And that looks like the content we've been playing around with.
Verifying Site and Entries2:48
Let's take a look at the database one more time. And that looks like the content we've been playing around with. Let's take a look at our site. All right, the site looks good. Everything seems to be running. Let's pop open the control panel. And let's just create a new entry. New database entry. It works. Save that.
Explaining JSON Storage Options3:17
It works. Save that. Pop over to SQL ACE. We'll refresh. And we're going to need to sort by created_at here. And you'll see new database entry. Now in case you're curious, all of the data outside that meta-level stuff like the slug, the status, the publish_date, all that is what we consider metadata on an entry. All of the field data will exist inside of a JSON field called data. JSON fields in MySQL are indexable, are searchable, and are actually quite performant, which gives
All of the field data will exist inside of a JSON field called data. JSON fields in MySQL are indexable, are searchable, and are actually quite performant, which gives us a huge leg up in simplicity. You do not need to manage migrations as you add and remove fields from your blueprints. Two other things to mention. First, if you want to keep something out of Eloquent, you do not want it in the database, you can switch it back over to the file driver. So maybe you want your blueprints in files, you want your assets in files, you want your forms in files, but you want your variable data, your entries, your globals, that kind of stuff in Eloquent, that's all you need to do.
forms in files, but you want your variable data, your entries, your globals, that kind of stuff in Eloquent, that's all you need to do. And the second thing is, users, by default, will stay in the files. So this users directory is going to still work by default when you're importing a new site. Of course, we have a separate Eloquent users package, install that, follow the steps, and you can put them in the database as well, which is great if you have thousands or hundreds of thousands of users, you do not want those in files. That'd be too slow. I hope this shows you how truly scalable Statamic is.
