diff --git a/.github/workflows/build-artifacts.yml b/.github/workflows/build-artifacts.yml index a3997cff306b8..4965acd5bf82a 100644 --- a/.github/workflows/build-artifacts.yml +++ b/.github/workflows/build-artifacts.yml @@ -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: diff --git a/api/memo_organizer.go b/api/memo_organizer.go index 10cc83bcbddd3..664ff1f0d2cd0 100644 --- a/api/memo_organizer.go +++ b/api/memo_organizer.go @@ -1,8 +1,6 @@ package api type MemoOrganizer struct { - ID int - // Domain specific fields MemoID int UserID int diff --git a/server/memo.go b/server/memo.go index 8f098333502fa..f9d5135d73fac 100644 --- a/server/memo.go +++ b/server/memo.go @@ -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) } } @@ -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) } } diff --git a/server/version/version.go b/server/version/version.go index 884b49f5253a1..726786c74f41d 100644 --- a/server/version/version.go +++ b/server/version/version.go @@ -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" { diff --git a/store/db/migration/dev/LATEST__SCHEMA.sql b/store/db/migration/dev/LATEST__SCHEMA.sql index 447052f77187b..fd58a200d7a1e 100644 --- a/store/db/migration/dev/LATEST__SCHEMA.sql +++ b/store/db/migration/dev/LATEST__SCHEMA.sql @@ -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, diff --git a/store/db/migration/prod/0.13/00__memo_relation.sql b/store/db/migration/prod/0.13/00__memo_relation.sql new file mode 100644 index 0000000000000..821a5984c0802 --- /dev/null +++ b/store/db/migration/prod/0.13/00__memo_relation.sql @@ -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) +); \ No newline at end of file diff --git a/store/db/migration/prod/0.13/01__remove_memo_organizer_id.sql b/store/db/migration/prod/0.13/01__remove_memo_organizer_id.sql new file mode 100644 index 0000000000000..6c4156c45b5f0 --- /dev/null +++ b/store/db/migration/prod/0.13/01__remove_memo_organizer_id.sql @@ -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; \ No newline at end of file diff --git a/store/db/migration/prod/LATEST__SCHEMA.sql b/store/db/migration/prod/LATEST__SCHEMA.sql index a5b3cfac05bcf..fd58a200d7a1e 100644 --- a/store/db/migration/prod/LATEST__SCHEMA.sql +++ b/store/db/migration/prod/LATEST__SCHEMA.sql @@ -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, @@ -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) ); \ No newline at end of file diff --git a/store/memo.go b/store/memo.go index 71bbfb02e09ce..45a1eb25adf81 100644 --- a/store/memo.go +++ b/store/memo.go @@ -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 diff --git a/store/memo_organizer.go b/store/memo_organizer.go index 844ba27e51618..1456e33db3900 100644 --- a/store/memo_organizer.go +++ b/store/memo_organizer.go @@ -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 @@ -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, @@ -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 @@ -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, @@ -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, diff --git a/store/store.go b/store/store.go index 7f8187c27e157..55668e7c25ecd 100644 --- a/store/store.go +++ b/store/store.go @@ -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 } @@ -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.