Skip to content

Commit

Permalink
Merge pull request #112 from bmf-san/feature/removed-archived-table
Browse files Browse the repository at this point in the history
Abolish logical deletion and unify to physical deletion
  • Loading branch information
bmf-san authored Apr 2, 2024
2 parents 885e5b9 + a9cef53 commit e0d3c71
Show file tree
Hide file tree
Showing 19 changed files with 633 additions and 986 deletions.
45 changes: 0 additions & 45 deletions app/interfaces/repository/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -1855,51 +1855,6 @@ func (pr *Post) DeleteByID(id int) (int, error) {
return 0, err
}

_, err = tx.Exec(`
INSERT INTO
archived_posts
SELECT
*
FROM
posts
WHERE
id = ?
`, id)
if err != nil {
_ = tx.Rollback()
return 0, nil
}

_, err = tx.Exec(`
INSERT INTO
archived_tag_post
SELECT
*
FROM
tag_post
WHERE
post_id = ?
`, id)
if err != nil {
_ = tx.Rollback()
return 0, err
}

_, err = tx.Exec(`
INSERT INTO
archived_comments
SELECT
*
FROM
comments
WHERE
post_id = ?
`, id)
if err != nil {
_ = tx.Rollback()
return 0, err
}

_, err = tx.Exec(`
DELETE FROM tag_post WHERE post_id = ?
`, id)
Expand Down
3 changes: 0 additions & 3 deletions doc/dbdoc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
| Name | Columns | Comment | Type |
| ---- | ------- | ------- | ---- |
| [admins](admins.md) | 6 | | BASE TABLE |
| [archived_comments](archived_comments.md) | 6 | | BASE TABLE |
| [archived_posts](archived_posts.md) | 9 | | BASE TABLE |
| [archived_tag_post](archived_tag_post.md) | 5 | | BASE TABLE |
| [categories](categories.md) | 4 | | BASE TABLE |
| [comments](comments.md) | 6 | | BASE TABLE |
| [posts](posts.md) | 9 | | BASE TABLE |
Expand Down
4 changes: 2 additions & 2 deletions doc/dbdoc/admins.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ CREATE TABLE `admins` (
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb3
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3
```

</details>
Expand All @@ -25,7 +25,7 @@ CREATE TABLE `admins` (

| Name | Type | Default | Nullable | Extra Definition | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | ---------------- | -------- | ------- | ------- |
| id | int unsigned | | false | auto_increment | [archived_posts](archived_posts.md) [posts](posts.md) | | |
| id | int unsigned | | false | auto_increment | [posts](posts.md) | | |
| name | varchar(255) | | false | | | | |
| email | varchar(255) | | false | | | | |
| password | varchar(255) | | false | | | | |
Expand Down
171 changes: 64 additions & 107 deletions doc/dbdoc/admins.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions doc/dbdoc/categories.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ CREATE TABLE `categories` (
`updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb3
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3
```

</details>
Expand All @@ -22,7 +22,7 @@ CREATE TABLE `categories` (

| Name | Type | Default | Nullable | Extra Definition | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | ---------------- | -------- | ------- | ------- |
| id | int unsigned | | false | auto_increment | [archived_posts](archived_posts.md) [posts](posts.md) | | |
| id | int unsigned | | false | auto_increment | [posts](posts.md) | | |
| name | varchar(255) | | false | | | | |
| created_at | datetime | CURRENT_TIMESTAMP | true | DEFAULT_GENERATED on update CURRENT_TIMESTAMP | | | |
| updated_at | datetime | CURRENT_TIMESTAMP | true | DEFAULT_GENERATED on update CURRENT_TIMESTAMP | | | |
Expand Down
159 changes: 58 additions & 101 deletions doc/dbdoc/categories.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions doc/dbdoc/comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ CREATE TABLE `comments` (
`updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `post_id` (`post_id`),
KEY `index_comments_status` (`status`),
CONSTRAINT `comments_ibfk_1` FOREIGN KEY (`post_id`) REFERENCES `posts` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3
```
Expand Down Expand Up @@ -44,7 +43,6 @@ CREATE TABLE `comments` (

| Name | Definition |
| ---- | ---------- |
| index_comments_status | KEY index_comments_status (status) USING BTREE |
| post_id | KEY post_id (post_id) USING BTREE |
| PRIMARY | PRIMARY KEY (id) USING BTREE |

Expand Down
98 changes: 49 additions & 49 deletions doc/dbdoc/comments.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions doc/dbdoc/posts.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ CREATE TABLE `posts` (
`updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `admin_id` (`admin_id`),
KEY `index_posts_status` (`status`),
KEY `index_posts_category_id` (`category_id`),
FULLTEXT KEY `index_title_md_body` (`title`,`md_body`) /*!50100 WITH PARSER `ngram` */ ,
CONSTRAINT `posts_ibfk_1` FOREIGN KEY (`admin_id`) REFERENCES `admins` (`id`),
CONSTRAINT `posts_ibfk_2` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=[Redacted by tbls] DEFAULT CHARSET=utf8mb3
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3
```

</details>
Expand Down Expand Up @@ -55,7 +55,7 @@ CREATE TABLE `posts` (
| ---- | ---------- |
| admin_id | KEY admin_id (admin_id) USING BTREE |
| index_posts_category_id | KEY index_posts_category_id (category_id) USING BTREE |
| index_posts_status | KEY index_posts_status (status) USING BTREE |
| index_title_md_body | KEY index_title_md_body (title, md_body) USING FULLTEXT |
| PRIMARY | PRIMARY KEY (id) USING BTREE |

## Relations
Expand Down
Loading

0 comments on commit e0d3c71

Please sign in to comment.