Skip to content

Commit

Permalink
Merge pull request #5 from plank/add-timelines
Browse files Browse the repository at this point in the history
Feature: Multiple Timelines
  • Loading branch information
a-drew authored Nov 10, 2021
2 parents 33e0ec1 + f79fade commit 70012cf
Show file tree
Hide file tree
Showing 29 changed files with 843 additions and 112 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Psalm

on:
push:
paths:
- '**.php'
- 'psalm.xml'

jobs:
psalm:
name: psalm
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none

- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: vendor
key: composer-vendor-${{ hashFiles('composer.json') }}

- name: Run composer install
run: composer update -n --prefer-dist --no-interaction

- name: Run psalm
run: ./vendor/bin/psalm -c psalm.xml.dist
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
composer update --${{ matrix.stability }} --no-interaction
- name: Install Legacy Factories Package
run: composer require "laravel/legacy-factories" --no-interaction --no-update
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `laravel-checkpoint` will be documented in this file

## 2.0.0 - 2021-11-09
- Adding the ability to have multiple timelines
- Adding the ability to set an Active Checkpoint

## 1.1.0 - 2021-10-29

- $unwatched replaced with $ignored / $excluded
Expand Down
35 changes: 28 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
- [Why Use This Package](#why-use-this-package)
- [Installation](#installation)
- [Concepts](#concepts)
- [Timelines](#timelines)
- [Checkpoints](#checkpoints)
- [Revisions](#revisions)
- [Usage](#usage)
- [Revisioning Models](#revisioning-models)
- [What gets Revisioned?](#what-gets-revisioned)
- [Start Revisioning Command](#start-revisioning-command)
- [Query Scopes](#query-scopes)
- [Active Checkpoint](#active-checkpoint)
- [at($moment)](#atmoment)
- [since($moment)](#sincemoment)
- [temporal($upper, $lower)](#temporalupper-lower)
Expand Down Expand Up @@ -45,19 +47,34 @@ composer require plank/laravel-checkpoint
```

## Concepts
### Timelines
A ```Timeline``` is a way to have completely separate views of your content. A ```Timeline``` allows you to filter the ```Revision```s of your models based on the ```Timeline``` it belongs to.

Table: ```timelines```

| Field | Type | Required | Default |
|-------------------|---------------------|:---------:|-----------------|
| id | bigIncrements || Increment |
| timeline_id | unsignedBigInteger || |
| title | string || |
| checkpoint_date | timestamp || |
| created_at | timestamp || |
| updated_at | timestamp || |

### Checkpoints
A ```Checkpoint``` is a point in time which is of interest. A ```Checkpoint``` allows you to filter the ```Revision```s
of your models based on the ```Checkpoint```'s ```checkpoint_date```.

Table: ```checkpoints```

| Field | Type | Required | Default |
|-------------------|----------------|:---------:|-----------------|
| id | bigIncrements || Increment |
| title | string || |
| checkpoint_date | timestamp || |
| created_at | timestamp || |
| updated_at | timestamp || |
| Field | Type | Required | Default |
|-------------------|---------------------|:---------:|-----------------|
| id | bigIncrements || Increment |
| timeline_id | unsignedBigInteger || |
| title | string || |
| checkpoint_date | timestamp || |
| created_at | timestamp || |
| updated_at | timestamp || |

### Revisions
A ```Revision``` references a record of a ```Model``` in a particular state at a particular point in time. When this
Expand Down Expand Up @@ -99,6 +116,10 @@ command will begin revisioning all of the *Models* which are using the ```HasRev
### Query Scopes
The way this package achieves it's goal is by adding scopes (and one global scope) to query models that have revisions.

#### Active Checkpoint
By setting the active checkpoint ```Checkpoint::setActive($checkpoint)```, all queries for revisioned models will be
scoped to that ```$checkpoint```. Also, when there is an active checkpoint set, any new revisions that get created will be associated with that ```$checkpoint```.

#### at($moment)
```php
/**
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
},
"require-dev": {
"laravel/legacy-factories": "^1.0.4",
"nunomaduro/larastan": "^0.7.8",
"orchestra/testbench": "^4.8 || ^5.2 || ^6.0",
"phpunit/phpunit": "^9.5",
"vimeo/psalm": "^4.8"
"psalm/plugin-laravel": "^1.4",
"vimeo/psalm": "^4.10"
},
"autoload": {
"psr-4": {
Expand Down
10 changes: 10 additions & 0 deletions config/checkpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@
*/
'checkpoint' => Plank\Checkpoint\Models\Checkpoint::class,

/*
* When using the "HasRevisions" trait from this package, we need to know which model
* should be used to retrieve your timelines. To extend or replace this functionality,
* change the value below with your full "timeline model" class name.
*/
'timeline' => Plank\Checkpoint\Models\Timeline::class,
],

/**
* The class responsible for storing and retrieving the active bulletin for each request
*/
'store' => Plank\Checkpoint\Stores\BasicCheckpointStore::class,
];
9 changes: 9 additions & 0 deletions database/factories/TimelineFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

use Plank\Checkpoint\Models\Timeline;

$factory->define(Timeline::class, function (Faker\Generator $faker) {
return [
'title' => $faker->words(3, true),
];
});
33 changes: 33 additions & 0 deletions database/migrations/2021_09_07_000001_create_timelines_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateTimelinesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('timelines', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('title');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('timelines');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddTimelinesToCheckpoints extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('checkpoints', function (Blueprint $table) {
$table->unsignedBigInteger('timeline_id')->after('id')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('checkpoints', function (Blueprint $table) {
$table->dropColumn('timeline_id');
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddTimelinesToRevisions extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('revisions', function (Blueprint $table) {
$table->unsignedBigInteger('timeline_id')->after('checkpoint_id')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('revisions', function (Blueprint $table) {
$table->dropColumn('timeline_id');
});
}
}
25 changes: 0 additions & 25 deletions phpstan.neon.dist

This file was deleted.

18 changes: 8 additions & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,15 @@
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<include>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage"/>
<text outputFile="build/coverage.txt"/>
</report>
</coverage>
</whitelist>
</filter>
<logging>
<junit outputFile="build/report.junit.xml"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
</phpunit>
Loading

0 comments on commit 70012cf

Please sign in to comment.