Skip to content

Commit bba3c81

Browse files
ryanmitchelljuliomenendezOliver Kaufmannbenajajasonvarga
authored
Support all models (#42)
Co-authored-by: Julio Carlos Menendez <[email protected]> Co-authored-by: Oliver Kaufmann <[email protected]> Co-authored-by: Benaja Hunzinger <[email protected]> Co-authored-by: Jason Varga <[email protected]> Co-authored-by: Maurice Wijnia <[email protected]> Co-authored-by: Frederik Sauer <[email protected]>
1 parent 929ffd0 commit bba3c81

File tree

102 files changed

+7430
-184
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+7430
-184
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2

.github/workflows/tests.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
php: [7.4, 7.3]
16-
laravel: [8.*]
15+
php: [8.0, 8.1]
16+
laravel: [8.*, 9.*]
1717
dependency-version: [prefer-lowest, prefer-stable]
1818

1919
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}
@@ -23,12 +23,16 @@ jobs:
2323
uses: actions/checkout@v1
2424

2525
- name: Setup PHP
26-
uses: shivammathur/setup-php@v1
26+
uses: shivammathur/setup-php@v2
2727
with:
2828
php-version: ${{ matrix.php }}
2929
extension-csv: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
3030
coverage: none
3131

32+
- name: Set PHP 8.1 Testbench
33+
run: composer require "orchestra/testbench ^6.22.0" --no-interaction --no-update
34+
if: matrix.laravel == '8.*' && matrix.php >= 8.1
35+
3236
- name: Install dependencies
3337
run: |
3438
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
composer.lock
22
vendor
33
.phpunit.result.cache
4+
.php_cs.cache

README.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
This package provides support for storing your Statamic data in a database rather than the filesystem.
44

5-
This driver currently supports entries but not taxonomies, navigations, globals, or form submissions. We'll be working on those in the future.
6-
75
## Installation
86

97
Install using Composer:
@@ -26,18 +24,43 @@ If you're starting from scratch, we can use traditional incrementing integers fo
2624

2725
- Delete `content/collections/pages/home.md`
2826
- Change the structure `tree` in `content/collections/pages.yaml` to `{}`.
27+
- Run `php artisan vendor:publish --provider="Statamic\Eloquent\ServiceProvider" --tag=migrations"`.
2928
- Run `php artisan vendor:publish --tag="statamic-eloquent-entries-table"`.
3029
- Run `php artisan migrate`.
3130

3231
### Starting from an existing site (using UUIDs)
3332

3433
If you're planning to use existing content, we can use the existing UUIDs. This will prevent you from needing to update any data or relationships.
3534

36-
- In the `config/statamic/eloquent-driver.php` file, change `model` to `UuidEntryModel`.
35+
- In the `config/statamic/eloquent-driver.php` file, change `model` to `\Statamic\Eloquent\Entries\UuidEntryModel`.
36+
- Run `php artisan vendor:publish --provider="Statamic\Eloquent\ServiceProvider" --tag=migrations"`.
3737
- Run `php artisan vendor:publish --tag="statamic-eloquent-entries-table-with-string-ids"`.
3838
- Run `php artisan migrate`.
39-
- Import entries into database with `php please eloquent:import-entries`.
39+
40+
## Configuration
41+
42+
The configuration file (`statamic.eloquent-driver`) allows you to choose which repositories you want to be driven by eloquent. By default, all are selected, but if you want to opt out simply change `driver` from `eloquent` to `file` for that repository.
43+
44+
You may also specify your own models for each repository, should you wish to use something different from the one provided.
45+
46+
## Importing existing file based content
47+
48+
We have provided imports from file based content for each repository, which can be run as follows:
49+
50+
- Assets: `php please eloquent:import-assets`
51+
- Blueprints and Fieldsets: `php please eloquent:import-blueprints`
52+
- Collections: `php please eloquent:import-collections`
53+
- Entries: `php please eloquent:import-entries`
54+
- Forms: `php please eloquent:import-forms`
55+
- Globals: `php please eloquent:import-globals`
56+
- Navs: `php please eloquent:import-navs`
57+
- Revisions: `php please eloquent:import-revisions`
58+
- Taxonomies: `php please eloquent:import-taxonomies`
4059

4160
## Storing Users in a Database
4261

43-
Statamic has a[ built-in users eloquent driver](https://statamic.dev/tips/storing-users-in-a-database) if you'd like to cross that bridge too.
62+
Statamic has a [built-in users eloquent driver](https://statamic.dev/tips/storing-users-in-a-database) if you'd like to cross that bridge too.
63+
64+
## Mixed driver entries and collections
65+
66+
This driver **does not** make it possible to have some collections/entries file driven and some eloquent driven. If that is your requirement you may want to look into using [Runway](https://statamic.com/addons/duncanmcclean/runway).

composer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,17 @@
2323
}
2424
},
2525
"require": {
26-
"statamic/cms": "^3.0"
26+
"php": "^8.0",
27+
"statamic/cms": "^3.3.31"
2728
},
2829
"require-dev": {
30+
"doctrine/dbal": "^3.3",
31+
"orchestra/testbench": "^6.7.0 || ^7.0",
2932
"phpunit/phpunit": "^9.4"
3033
},
34+
"scripts": {
35+
"test": "phpunit"
36+
},
3137
"config": {
3238
"allow-plugins": {
3339
"pixelfear/composer-dist-plugin": true

config/eloquent-driver.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,65 @@
22

33
return [
44

5+
'connection' => env('STATAMIC_ELOQUENT_CONNECTION', ''),
6+
'table_prefix' => env('STATAMIC_ELOQUENT_PREFIX', ''),
7+
8+
'assets' => [
9+
'driver' => 'eloquent',
10+
'container_model' => \Statamic\Eloquent\Assets\AssetContainerModel::class,
11+
'model' => \Statamic\Eloquent\Assets\AssetModel::class,
12+
],
13+
14+
'blueprints' => [
15+
'driver' => 'eloquent',
16+
'blueprint_model' => \Statamic\Eloquent\Fields\BlueprintModel::class,
17+
'fieldset_model' => \Statamic\Eloquent\Fields\FieldsetModel::class,
18+
],
19+
20+
'collections' => [
21+
'driver' => 'eloquent',
22+
'model' => \Statamic\Eloquent\Collections\CollectionModel::class,
23+
'tree' => \Statamic\Eloquent\Structures\CollectionTree::class,
24+
'tree_model' => \Statamic\Eloquent\Structures\TreeModel::class,
25+
],
26+
527
'entries' => [
28+
'driver' => 'eloquent',
629
'model' => \Statamic\Eloquent\Entries\EntryModel::class,
30+
'entry' => \Statamic\Eloquent\Entries\Entry::class,
31+
],
32+
33+
'forms' => [
34+
'driver' => 'eloquent',
35+
'model' => \Statamic\Eloquent\Forms\FormModel::class,
36+
'submission_model' => \Statamic\Eloquent\Forms\SubmissionModel::class,
737
],
838

39+
'global_sets' => [
40+
'driver' => 'eloquent',
41+
'model' => \Statamic\Eloquent\Globals\GlobalSetModel::class,
42+
'variables_model' => \Statamic\Eloquent\Globals\VariablesModel::class,
43+
],
44+
45+
'navigations' => [
46+
'driver' => 'eloquent',
47+
'model' => \Statamic\Eloquent\Structures\NavModel::class,
48+
'tree' => \Statamic\Eloquent\Structures\NavTree::class,
49+
'tree_model' => \Statamic\Eloquent\Structures\TreeModel::class,
50+
],
51+
52+
'revisions' => [
53+
'driver' => 'eloquent',
54+
'model' => \Statamic\Eloquent\Revisions\RevisionModel::class,
55+
],
56+
57+
'taxonomies' => [
58+
'driver' => 'eloquent',
59+
'model' => \Statamic\Eloquent\Taxonomies\TaxonomyModel::class,
60+
],
61+
62+
'terms' => [
63+
'driver' => 'eloquent',
64+
'model' => \Statamic\Eloquent\Taxonomies\TermModel::class,
65+
],
966
];
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Support\Facades\Schema;
5+
use Statamic\Eloquent\Database\BaseMigration as Migration;
6+
7+
return new class extends Migration {
8+
public function up()
9+
{
10+
Schema::create($this->prefix('asset_containers'), function (Blueprint $table) {
11+
$table->id();
12+
$table->string('handle')->unique();
13+
$table->string('title');
14+
$table->string('disk');
15+
$table->json('settings')->nullable();
16+
$table->timestamps();
17+
});
18+
}
19+
20+
public function down()
21+
{
22+
Schema::dropIfExists($this->prefix('asset_containers'));
23+
}
24+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Support\Facades\Schema;
5+
use Statamic\Eloquent\Database\BaseMigration as Migration;
6+
7+
return new class extends Migration {
8+
public function up()
9+
{
10+
Schema::create($this->prefix('assets_meta'), function (Blueprint $table) {
11+
$table->id();
12+
$table->string('handle')->index();
13+
$table->json('data')->nullable();
14+
$table->timestamps();
15+
});
16+
}
17+
18+
19+
public function down()
20+
{
21+
Schema::dropIfExists($this->prefix('assets_meta'));
22+
}
23+
};
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Support\Carbon;
5+
use Illuminate\Support\Facades\Schema;
6+
use Statamic\Eloquent\Database\BaseMigration as Migration;
7+
8+
return new class extends Migration {
9+
public function up()
10+
{
11+
Schema::create($this->prefix('blueprints'), function (Blueprint $table) {
12+
$table->id();
13+
$table->string('namespace')->nullable()->default(null)->index();
14+
$table->string('handle');
15+
$table->json('data');
16+
$table->timestamps();
17+
18+
$table->unique(['handle', 'namespace']);
19+
});
20+
21+
$this->seedDefaultBlueprint();
22+
}
23+
24+
public function down()
25+
{
26+
Schema::dropIfExists($this->prefix('blueprints'));
27+
}
28+
29+
public function seedDefaultBlueprint()
30+
{
31+
try {
32+
$config = json_encode([
33+
'fields' => [
34+
[
35+
'field' => [
36+
'type' => 'markdown',
37+
'display' => 'Content',
38+
'localizable' => true,
39+
],
40+
'handle' => 'content',
41+
],
42+
[
43+
'field' => [
44+
'type' => 'users',
45+
'display' => 'Author',
46+
'default' => 'current',
47+
'localizable' => true,
48+
'max_items' => 1,
49+
],
50+
'handle' => 'author',
51+
],
52+
[
53+
'field' => [
54+
'type' => 'template',
55+
'display' => 'Template',
56+
'localizable' => true,
57+
],
58+
'handle' => 'template',
59+
],
60+
],
61+
]);
62+
} catch (\JsonException $e) {
63+
$config = '[]';
64+
}
65+
66+
DB::table($this->prefix('blueprints'))->insert([
67+
'namespace' => null,
68+
'handle' => 'default',
69+
'data' => $config,
70+
'created_at' => Carbon::now(),
71+
]);
72+
}
73+
};
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Support\Facades\Schema;
5+
use Statamic\Eloquent\Database\BaseMigration as Migration;
6+
7+
return new class extends Migration {
8+
public function up()
9+
{
10+
Schema::create($this->prefix('collections'), function (Blueprint $table) {
11+
$table->id();
12+
$table->string('handle')->unique();
13+
$table->string('title');
14+
$table->json('settings')->nullable();
15+
$table->timestamps();
16+
});
17+
}
18+
19+
public function down()
20+
{
21+
Schema::dropIfExists($this->prefix('collections'));
22+
}
23+
};

0 commit comments

Comments
 (0)