Skip to content

Commit

Permalink
chore: upgrade version 0.13.0 (#1685)
Browse files Browse the repository at this point in the history
* chore: upgrade version `0.13.0`

* chore: update
  • Loading branch information
boojack authored May 20, 2023
1 parent d80aa67 commit 1d7627d
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 62 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/build-artifacts.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
name: Memos Build
name: build-artifacts

on:
push:
branches:
- main
# Run on pushing branches like `release/1.0.0`
- "release/*.*.*"

jobs:
build:
build-artifacts:
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down
2 changes: 0 additions & 2 deletions api/memo_organizer.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package api

type MemoOrganizer struct {
ID int

// Domain specific fields
MemoID int
UserID int
Expand Down
68 changes: 32 additions & 36 deletions server/memo.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,13 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
}
}

if s.Profile.IsDev() {
for _, memoRelationUpsert := range memoCreate.RelationList {
if _, err := s.Store.UpsertMemoRelation(ctx, &store.MemoRelationMessage{
MemoID: memo.ID,
RelatedMemoID: memoRelationUpsert.RelatedMemoID,
Type: store.MemoRelationType(memoRelationUpsert.Type),
}); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to upsert memo relation").SetInternal(err)
}
for _, memoRelationUpsert := range memoCreate.RelationList {
if _, err := s.Store.UpsertMemoRelation(ctx, &store.MemoRelationMessage{
MemoID: memo.ID,
RelatedMemoID: memoRelationUpsert.RelatedMemoID,
Type: store.MemoRelationType(memoRelationUpsert.Type),
}); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to upsert memo relation").SetInternal(err)
}
}

Expand Down Expand Up @@ -187,34 +185,32 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
}
}

if s.Profile.IsDev() {
patchMemoRelationList := make([]*api.MemoRelation, 0)
for _, memoRelationUpsert := range memoPatch.RelationList {
patchMemoRelationList = append(patchMemoRelationList, &api.MemoRelation{
MemoID: memo.ID,
RelatedMemoID: memoRelationUpsert.RelatedMemoID,
Type: memoRelationUpsert.Type,
})
}
addedMemoRelationList, removedMemoRelationList := getMemoRelationListDiff(memo.RelationList, patchMemoRelationList)
for _, memoRelation := range addedMemoRelationList {
if _, err := s.Store.UpsertMemoRelation(ctx, &store.MemoRelationMessage{
MemoID: memo.ID,
RelatedMemoID: memoRelation.RelatedMemoID,
Type: store.MemoRelationType(memoRelation.Type),
}); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to upsert memo relation").SetInternal(err)
}
patchMemoRelationList := make([]*api.MemoRelation, 0)
for _, memoRelationUpsert := range memoPatch.RelationList {
patchMemoRelationList = append(patchMemoRelationList, &api.MemoRelation{
MemoID: memo.ID,
RelatedMemoID: memoRelationUpsert.RelatedMemoID,
Type: memoRelationUpsert.Type,
})
}
addedMemoRelationList, removedMemoRelationList := getMemoRelationListDiff(memo.RelationList, patchMemoRelationList)
for _, memoRelation := range addedMemoRelationList {
if _, err := s.Store.UpsertMemoRelation(ctx, &store.MemoRelationMessage{
MemoID: memo.ID,
RelatedMemoID: memoRelation.RelatedMemoID,
Type: store.MemoRelationType(memoRelation.Type),
}); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to upsert memo relation").SetInternal(err)
}
for _, memoRelation := range removedMemoRelationList {
memoRelationType := store.MemoRelationType(memoRelation.Type)
if err := s.Store.DeleteMemoRelation(ctx, &store.DeleteMemoRelationMessage{
MemoID: &memo.ID,
RelatedMemoID: &memoRelation.RelatedMemoID,
Type: &memoRelationType,
}); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to delete memo relation").SetInternal(err)
}
}
for _, memoRelation := range removedMemoRelationList {
memoRelationType := store.MemoRelationType(memoRelation.Type)
if err := s.Store.DeleteMemoRelation(ctx, &store.DeleteMemoRelationMessage{
MemoID: &memo.ID,
RelatedMemoID: &memoRelation.RelatedMemoID,
Type: &memoRelationType,
}); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to delete memo relation").SetInternal(err)
}
}

Expand Down
4 changes: 2 additions & 2 deletions server/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (

// Version is the service current released version.
// Semantic versioning: https://semver.org/
var Version = "0.12.2"
var Version = "0.13.0"

// DevVersion is the service current development version.
var DevVersion = "0.12.2"
var DevVersion = "0.13.0"

func GetCurrentVersion(mode string) string {
if mode == "dev" || mode == "demo" {
Expand Down
1 change: 0 additions & 1 deletion store/db/migration/dev/LATEST__SCHEMA.sql
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ CREATE TABLE memo (

-- memo_organizer
CREATE TABLE memo_organizer (
id INTEGER PRIMARY KEY AUTOINCREMENT,
memo_id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
pinned INTEGER NOT NULL CHECK (pinned IN (0, 1)) DEFAULT 0,
Expand Down
7 changes: 7 additions & 0 deletions store/db/migration/prod/0.13/00__memo_relation.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- memo_relation
CREATE TABLE memo_relation (
memo_id INTEGER NOT NULL,
related_memo_id INTEGER NOT NULL,
type TEXT NOT NULL,
UNIQUE(memo_id, related_memo_id, type)
);
22 changes: 22 additions & 0 deletions store/db/migration/prod/0.13/01__remove_memo_organizer_id.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
DROP TABLE IF EXISTS memo_organizer_temp;

CREATE TABLE memo_organizer_temp (
memo_id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
pinned INTEGER NOT NULL CHECK (pinned IN (0, 1)) DEFAULT 0,
UNIQUE(memo_id, user_id)
);

INSERT INTO
memo_organizer_temp (memo_id, user_id, pinned)
SELECT
memo_id,
user_id,
pinned
FROM
memo_organizer;

DROP TABLE memo_organizer;

ALTER TABLE
memo_organizer_temp RENAME TO memo_organizer;
9 changes: 8 additions & 1 deletion store/db/migration/prod/LATEST__SCHEMA.sql
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ CREATE TABLE memo (

-- memo_organizer
CREATE TABLE memo_organizer (
id INTEGER PRIMARY KEY AUTOINCREMENT,
memo_id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
pinned INTEGER NOT NULL CHECK (pinned IN (0, 1)) DEFAULT 0,
Expand Down Expand Up @@ -123,4 +122,12 @@ CREATE TABLE idp (
type TEXT NOT NULL,
identifier_filter TEXT NOT NULL DEFAULT '',
config TEXT NOT NULL DEFAULT '{}'
);

-- memo_relation
CREATE TABLE memo_relation (
memo_id INTEGER NOT NULL,
related_memo_id INTEGER NOT NULL,
type TEXT NOT NULL,
UNIQUE(memo_id, related_memo_id, type)
);
6 changes: 2 additions & 4 deletions store/memo.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ func (s *Store) ComposeMemo(ctx context.Context, memo *api.Memo) (*api.Memo, err
if err := s.ComposeMemoResourceList(ctx, memo); err != nil {
return nil, err
}
if s.Profile.IsDev() {
if err := s.ComposeMemoRelationList(ctx, memo); err != nil {
return nil, err
}
if err := s.ComposeMemoRelationList(ctx, memo); err != nil {
return nil, err
}

return memo, nil
Expand Down
9 changes: 1 addition & 8 deletions store/memo_organizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
// memoOrganizerRaw is the store model for an MemoOrganizer.
// Fields have exactly the same meanings as MemoOrganizer.
type memoOrganizerRaw struct {
ID int

// Domain specific fields
MemoID int
UserID int
Expand All @@ -23,8 +21,6 @@ type memoOrganizerRaw struct {

func (raw *memoOrganizerRaw) toMemoOrganizer() *api.MemoOrganizer {
return &api.MemoOrganizer{
ID: raw.ID,

MemoID: raw.MemoID,
UserID: raw.UserID,
Pinned: raw.Pinned,
Expand Down Expand Up @@ -87,7 +83,6 @@ func (s *Store) DeleteMemoOrganizer(ctx context.Context, delete *api.MemoOrganiz
func findMemoOrganizer(ctx context.Context, tx *sql.Tx, find *api.MemoOrganizerFind) (*memoOrganizerRaw, error) {
query := `
SELECT
id,
memo_id,
user_id,
pinned
Expand All @@ -106,7 +101,6 @@ func findMemoOrganizer(ctx context.Context, tx *sql.Tx, find *api.MemoOrganizerF

var memoOrganizerRaw memoOrganizerRaw
if err := row.Scan(
&memoOrganizerRaw.ID,
&memoOrganizerRaw.MemoID,
&memoOrganizerRaw.UserID,
&memoOrganizerRaw.Pinned,
Expand All @@ -132,11 +126,10 @@ func upsertMemoOrganizer(ctx context.Context, tx *sql.Tx, upsert *api.MemoOrgani
ON CONFLICT(memo_id, user_id) DO UPDATE
SET
pinned = EXCLUDED.pinned
RETURNING id, memo_id, user_id, pinned
RETURNING memo_id, user_id, pinned
`
var memoOrganizer api.MemoOrganizer
if err := tx.QueryRowContext(ctx, query, upsert.MemoID, upsert.UserID, upsert.Pinned).Scan(
&memoOrganizer.ID,
&memoOrganizer.MemoID,
&memoOrganizer.UserID,
&memoOrganizer.Pinned,
Expand Down
8 changes: 3 additions & 5 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (s *Store) Vacuum(ctx context.Context) error {
return nil
}

func (s *Store) vacuumImpl(ctx context.Context, tx *sql.Tx) error {
func (*Store) vacuumImpl(ctx context.Context, tx *sql.Tx) error {
if err := vacuumMemo(ctx, tx); err != nil {
return err
}
Expand All @@ -70,10 +70,8 @@ func (s *Store) vacuumImpl(ctx context.Context, tx *sql.Tx) error {
if err := vacuumMemoResource(ctx, tx); err != nil {
return err
}
if s.Profile.IsDev() {
if err := vacuumMemoRelations(ctx, tx); err != nil {
return err
}
if err := vacuumMemoRelations(ctx, tx); err != nil {
return err
}
if err := vacuumTag(ctx, tx); err != nil {
// Prevent revive warning.
Expand Down

0 comments on commit 1d7627d

Please sign in to comment.