Add migration script, basic articles tables

This commit is contained in:
myrmidex 2025-06-28 02:35:58 +02:00
parent 7923019d18
commit 9e2babb298
8 changed files with 217 additions and 2 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/vendor/ /vendor/
/.idea /.idea
/storage

View file

@ -2,3 +2,6 @@ # Lemmy Poster
A script that watches websites for new articles. If present, the new article will be posted to a Lemmy community. A script that watches websites for new articles. If present, the new article will be posted to a Lemmy community.
## Install
`touch storage/database.sqlite`

20
bin/migrate.php Executable file
View file

@ -0,0 +1,20 @@
#!/usr/bin/env php
<?php
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../bootstrap/database.php';
use Illuminate\Filesystem\Filesystem;
use Illuminate\Database\Migrations\DatabaseMigrationRepository;
use Illuminate\Database\Migrations\Migrator;
$repository = new DatabaseMigrationRepository($capsule->getDatabaseManager(), 'migrations');
$migrator = new Migrator($repository, $capsule->getDatabaseManager(), new Filesystem);
if (! $repository->repositoryExists()) {
$repository->createRepository();
echo "Migration table created.\n";
}
$migrator->run(__DIR__ . '/../database/migrations');
echo "Migrations complete.\n";

14
bootstrap/database.php Normal file
View file

@ -0,0 +1,14 @@
<?php
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'sqlite',
'database' => __DIR__ . '/../storage/database.sqlite',
'prefix' => '',
]);
$capsule->setAsGlobal();
$capsule->bootEloquent();

View file

@ -8,7 +8,8 @@
"vlucas/phpdotenv": "5.6.x-dev", "vlucas/phpdotenv": "5.6.x-dev",
"illuminate/collections": "^13.0@dev", "illuminate/collections": "^13.0@dev",
"illuminate/database": "^13.0@dev", "illuminate/database": "^13.0@dev",
"illuminate/events": "^13.0@dev" "illuminate/events": "^13.0@dev",
"illuminate/filesystem": "^13.0@dev"
}, },
"license": "GPL-3.0-only", "license": "GPL-3.0-only",
"autoload": { "autoload": {

135
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "4931f0d137b3a31564c33155a498a8ec", "content-hash": "33675bf6fade06847537e0f425f59267",
"packages": [ "packages": [
{ {
"name": "brick/math", "name": "brick/math",
@ -999,6 +999,74 @@
}, },
"time": "2025-05-13T22:04:04+00:00" "time": "2025-05-13T22:04:04+00:00"
}, },
{
"name": "illuminate/filesystem",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/illuminate/filesystem.git",
"reference": "1114355d9405a76a866a043e0d0974919d858dd9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/illuminate/filesystem/zipball/1114355d9405a76a866a043e0d0974919d858dd9",
"reference": "1114355d9405a76a866a043e0d0974919d858dd9",
"shasum": ""
},
"require": {
"illuminate/collections": "^13.0",
"illuminate/contracts": "^13.0",
"illuminate/macroable": "^13.0",
"illuminate/support": "^13.0",
"php": "^8.3",
"symfony/finder": "^7.4.0|^8.0.0"
},
"suggest": {
"ext-fileinfo": "Required to use the Filesystem class.",
"ext-ftp": "Required to use the Flysystem FTP driver.",
"ext-hash": "Required to use the Filesystem class.",
"illuminate/http": "Required for handling uploaded files (^13.0).",
"league/flysystem": "Required to use the Flysystem local driver (^3.25.1).",
"league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^3.25.1).",
"league/flysystem-ftp": "Required to use the Flysystem FTP driver (^3.25.1).",
"league/flysystem-sftp-v3": "Required to use the Flysystem SFTP driver (^3.25.1).",
"psr/http-message": "Required to allow Storage::put to accept a StreamInterface (^1.0).",
"symfony/filesystem": "Required to enable support for relative symbolic links (^7.4|^8.0).",
"symfony/mime": "Required to enable support for guessing extensions (^7.4|^8.0)."
},
"default-branch": true,
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "13.0.x-dev"
}
},
"autoload": {
"files": [
"functions.php"
],
"psr-4": {
"Illuminate\\Filesystem\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Taylor Otwell",
"email": "taylor@laravel.com"
}
],
"description": "The Illuminate Filesystem package.",
"homepage": "https://laravel.com",
"support": {
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"time": "2025-06-19T00:51:36+00:00"
},
{ {
"name": "illuminate/macroable", "name": "illuminate/macroable",
"version": "dev-master", "version": "dev-master",
@ -2074,6 +2142,70 @@
], ],
"time": "2024-09-25T14:21:43+00:00" "time": "2024-09-25T14:21:43+00:00"
}, },
{
"name": "symfony/finder",
"version": "8.0.x-dev",
"source": {
"type": "git",
"url": "https://github.com/symfony/finder.git",
"reference": "67ffe337ccb03d95abee819ae65abe3957b027ff"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/finder/zipball/67ffe337ccb03d95abee819ae65abe3957b027ff",
"reference": "67ffe337ccb03d95abee819ae65abe3957b027ff",
"shasum": ""
},
"require": {
"php": ">=8.4"
},
"require-dev": {
"symfony/filesystem": "^7.4|^8.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\Finder\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Finds files and directories via an intuitive fluent interface",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/finder/tree/8.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2025-06-03T12:29:50+00:00"
},
{ {
"name": "symfony/polyfill-ctype", "name": "symfony/polyfill-ctype",
"version": "1.x-dev", "version": "1.x-dev",
@ -2737,6 +2869,7 @@
"illuminate/collections": 20, "illuminate/collections": 20,
"illuminate/database": 20, "illuminate/database": 20,
"illuminate/events": 20, "illuminate/events": 20,
"illuminate/filesystem": 20,
"monolog/monolog": 20, "monolog/monolog": 20,
"vlucas/phpdotenv": 20 "vlucas/phpdotenv": 20
}, },

View file

@ -0,0 +1,21 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Migrations\Migration;
return new class extends Migration {
public function up(): void {
Capsule::schema()->create('articles', function (Blueprint $table) {
$table->id();
$table->string('url')->unique();
$table->string('title')->nullable();
$table->json('data')->nullable();
$table->timestamp('seen_at')->useCurrent();
});
}
public function down(): void {
Capsule::schema()->dropIfExists('articles');
}
};

View file

@ -0,0 +1,22 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Migrations\Migration;
return new class extends Migration {
public function up(): void {
Capsule::schema()->create('article_posted', function (Blueprint $table) {
$table->id();
$table->foreignId('article_id')->constrained('articles')->onDelete('cascade');
$table->string('community');
$table->timestamp('posted_at')->useCurrent();
$table->json('response')->nullable();
});
}
public function down(): void
{
Capsule::schema()->dropIfExists('article_posted');
}
};