first commit
This commit is contained in:
31
database/migrations/003_create_posts.php
Normal file
31
database/migrations/003_create_posts.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Migration 003 — Création de la table des articles.
|
||||
*
|
||||
* author_id est une clé étrangère nullable vers users(id).
|
||||
* SET NULL garantit que les articles sont conservés si l'auteur est supprimé.
|
||||
*
|
||||
* Index explicite sur author_id : SQLite n'indexe pas automatiquement les FK.
|
||||
* Utilisé par findByUserId() (liste admin) et par les filtres de recherche FTS.
|
||||
*/
|
||||
return [
|
||||
'up' => "
|
||||
CREATE TABLE IF NOT EXISTS posts (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
title TEXT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
slug TEXT UNIQUE NOT NULL DEFAULT '',
|
||||
author_id INTEGER REFERENCES users(id) ON DELETE SET NULL,
|
||||
category_id INTEGER REFERENCES categories(id) ON DELETE SET NULL,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_posts_author_id ON posts(author_id);
|
||||
",
|
||||
|
||||
'down' => "
|
||||
DROP INDEX IF EXISTS idx_posts_author_id;
|
||||
DROP TABLE IF EXISTS posts;
|
||||
",
|
||||
];
|
||||
Reference in New Issue
Block a user