first commit
This commit is contained in:
25
database/migrations/008_sync_posts_fts_when_users_change.php
Normal file
25
database/migrations/008_sync_posts_fts_when_users_change.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'up' => "
|
||||
DROP TRIGGER IF EXISTS posts_fts_users_delete;
|
||||
DROP TRIGGER IF EXISTS posts_fts_users_update;
|
||||
|
||||
CREATE TRIGGER IF NOT EXISTS posts_fts_users_update
|
||||
AFTER UPDATE OF username ON users BEGIN
|
||||
DELETE FROM posts_fts
|
||||
WHERE rowid IN (SELECT id FROM posts WHERE author_id = NEW.id);
|
||||
|
||||
INSERT INTO posts_fts(rowid, title, content, author_username)
|
||||
SELECT p.id,
|
||||
p.title,
|
||||
COALESCE(strip_tags(p.content), ''),
|
||||
NEW.username
|
||||
FROM posts p
|
||||
WHERE p.author_id = NEW.id;
|
||||
END;
|
||||
",
|
||||
'down' => "
|
||||
DROP TRIGGER IF EXISTS posts_fts_users_update;
|
||||
",
|
||||
];
|
||||
Reference in New Issue
Block a user