From 9e2babb2981adc6996148b6408b32d32265ee7d9 Mon Sep 17 00:00:00 2001 From: myrmidex Date: Sat, 28 Jun 2025 02:35:58 +0200 Subject: [PATCH] Add migration script, basic articles tables --- .gitignore | 1 + README.md | 3 + bin/migrate.php | 20 +++ bootstrap/database.php | 14 ++ composer.json | 3 +- composer.lock | 135 +++++++++++++++++- ...025_06_26_000000_create_articles_table.php | 21 +++ ...26_000001_create_articles_posted_table.php | 22 +++ 8 files changed, 217 insertions(+), 2 deletions(-) create mode 100755 bin/migrate.php create mode 100644 bootstrap/database.php create mode 100644 database/migrations/2025_06_26_000000_create_articles_table.php create mode 100644 database/migrations/2025_06_26_000001_create_articles_posted_table.php diff --git a/.gitignore b/.gitignore index bf7e5af..69c7649 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /vendor/ /.idea +/storage \ No newline at end of file diff --git a/README.md b/README.md index ed78c99..bebeb5e 100644 --- a/README.md +++ b/README.md @@ -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. +## Install + +`touch storage/database.sqlite` \ No newline at end of file diff --git a/bin/migrate.php b/bin/migrate.php new file mode 100755 index 0000000..a037924 --- /dev/null +++ b/bin/migrate.php @@ -0,0 +1,20 @@ +#!/usr/bin/env php +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"; diff --git a/bootstrap/database.php b/bootstrap/database.php new file mode 100644 index 0000000..a27ce16 --- /dev/null +++ b/bootstrap/database.php @@ -0,0 +1,14 @@ +addConnection([ + 'driver' => 'sqlite', + 'database' => __DIR__ . '/../storage/database.sqlite', + 'prefix' => '', +]); + +$capsule->setAsGlobal(); +$capsule->bootEloquent(); diff --git a/composer.json b/composer.json index 243ab79..f65f380 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,8 @@ "vlucas/phpdotenv": "5.6.x-dev", "illuminate/collections": "^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", "autoload": { diff --git a/composer.lock b/composer.lock index fd4bc18..e7d2b59 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4931f0d137b3a31564c33155a498a8ec", + "content-hash": "33675bf6fade06847537e0f425f59267", "packages": [ { "name": "brick/math", @@ -999,6 +999,74 @@ }, "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", "version": "dev-master", @@ -2074,6 +2142,70 @@ ], "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", "version": "1.x-dev", @@ -2737,6 +2869,7 @@ "illuminate/collections": 20, "illuminate/database": 20, "illuminate/events": 20, + "illuminate/filesystem": 20, "monolog/monolog": 20, "vlucas/phpdotenv": 20 }, diff --git a/database/migrations/2025_06_26_000000_create_articles_table.php b/database/migrations/2025_06_26_000000_create_articles_table.php new file mode 100644 index 0000000..fb4ad1c --- /dev/null +++ b/database/migrations/2025_06_26_000000_create_articles_table.php @@ -0,0 +1,21 @@ +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'); + } +}; diff --git a/database/migrations/2025_06_26_000001_create_articles_posted_table.php b/database/migrations/2025_06_26_000001_create_articles_posted_table.php new file mode 100644 index 0000000..26e1a09 --- /dev/null +++ b/database/migrations/2025_06_26_000001_create_articles_posted_table.php @@ -0,0 +1,22 @@ +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'); + } +};