From 6e690ea4da4494b71eeac2406264fc048512d636 Mon Sep 17 00:00:00 2001 From: Sung Won Cho Date: Sun, 29 Mar 2020 09:43:42 +1100 Subject: [PATCH] Fix rules (#438) * Fix network * Fix migrations for table that no longer exist * Document changed behavior --- CHANGELOG.md | 8 ++++ SELF_HOSTING.md | 2 + host/docker/build.sh | 2 +- host/docker/docker-compose.yml | 3 +- ...0191028103522-create-weekly-repetition.sql | 41 +---------------- ...20191225185502-populate-digest-version.sql | 14 +----- ...191226093447-add-digest-id-primary-key.sql | 7 +-- ...9-use-id-in-digest-notes-joining-table.sql | 45 +------------------ ...20191226152111-delete-outdated-digests.sql | 11 +---- 9 files changed, 22 insertions(+), 111 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70ca4e1f..807798d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ All notable changes to the projects under this repository will be documented in The following log documents the history of the server project. +### 1.0.1 - 2020-03-29 + +- Fix fresh install running migrations against tables that no longer exists. + ### 1.0.0 - 2020-03-22 #### Fixed @@ -21,6 +25,10 @@ The following log documents the history of the server project. - Remove the deprecated features related to digests and repetition rules (#432) - Remove the migration for the deprecated, encrypted Dnote (#433) +#### Changed + +- Please set `OnPremise` environment to `true` in order to automatically use the Pro version. + ### 0.5.0 - 2020-02-06 #### Changed diff --git a/SELF_HOSTING.md b/SELF_HOSTING.md index 58d17dd2..857b17e3 100644 --- a/SELF_HOSTING.md +++ b/SELF_HOSTING.md @@ -22,6 +22,7 @@ mv ./dnote-server /usr/local/bin ```bash GO_ENV=PRODUCTION \ +OnPremise=true \ DBHost=localhost \ DBPort=5432 \ DBName=dnote \ @@ -104,6 +105,7 @@ RestartSec=3 WorkingDirectory=/home/$user ExecStart=/usr/local/bin/dnote-server start Environment=GO_ENV=PRODUCTION +Environment=OnPremise=true Environment=DBHost=localhost Environment=DBPort=5432 Environment=DBName=dnote diff --git a/host/docker/build.sh b/host/docker/build.sh index 342f1a3b..3ea9c143 100755 --- a/host/docker/build.sh +++ b/host/docker/build.sh @@ -10,4 +10,4 @@ tarballName="dnote_server_${version}_linux_amd64.tar.gz" # copy over the build artifact to the Docker build context cp "$projectDir/build/server/$tarballName" "$dir" -docker build -t dnote/dnote:"$version" --build-arg tarballName="$tarballName" . +docker build --network=host -t dnote/dnote:"$version" --build-arg tarballName="$tarballName" . diff --git a/host/docker/docker-compose.yml b/host/docker/docker-compose.yml index 90e31ada..633d4f58 100644 --- a/host/docker/docker-compose.yml +++ b/host/docker/docker-compose.yml @@ -12,7 +12,7 @@ services: restart: always dnote: - image: dnote/dnote + image: dnote/dnote:1.0.1 environment: GO_ENV: PRODUCTION DBSkipSSL: "true" @@ -22,6 +22,7 @@ services: DBUser: dnote DBPassword: dnote WebURL: localhost:3000 + OnPremise: "true" SmtpHost: SmtpPort: SmtpUsername: diff --git a/pkg/server/database/migrations/20191028103522-create-weekly-repetition.sql b/pkg/server/database/migrations/20191028103522-create-weekly-repetition.sql index c164cd7a..22ac6f3a 100644 --- a/pkg/server/database/migrations/20191028103522-create-weekly-repetition.sql +++ b/pkg/server/database/migrations/20191028103522-create-weekly-repetition.sql @@ -1,45 +1,8 @@ +-- this migration is noop because repetition_rules have been removed + -- create-weekly-repetition.sql creates the default repetition rules for the users -- that used to have the weekly email digest on Friday 20:00 UTC -- +migrate Up -WITH next_friday AS ( - SELECT * FROM generate_series( - CURRENT_DATE + INTERVAL '1 day', - CURRENT_DATE + INTERVAL '7 days', - INTERVAL '1 day' - ) AS day -) -INSERT INTO repetition_rules -( - user_id, - title, - enabled, - hour, - minute, - frequency, - last_active, - book_domain, - note_count, - next_active -) SELECT - t1.id, - 'Default weekly repetition', - true, - 20, - 0, - 604800000, -- 7 days - 0, - 'all', - 20, - extract(epoch FROM date_trunc('day', t1.day) + INTERVAL '20 hours') * 1000 -FROM ( - SELECT * FROM users - INNER JOIN next_friday ON EXTRACT(ISODOW FROM day) = '5' -- next friday - WHERE users.cloud = true -) as t1; - - -- +migrate Down - -DELETE FROM repetition_rules WHERE title = 'Default weekly repetition' AND enabled AND hour = 8 AND minute = 0; diff --git a/pkg/server/database/migrations/20191225185502-populate-digest-version.sql b/pkg/server/database/migrations/20191225185502-populate-digest-version.sql index 7bc4c868..73098dbf 100644 --- a/pkg/server/database/migrations/20191225185502-populate-digest-version.sql +++ b/pkg/server/database/migrations/20191225185502-populate-digest-version.sql @@ -1,19 +1,9 @@ +-- this migration is noop because digests have been removed + -- populate-digest-version.sql populates the `version` column for the digests -- by assigining an incremental integer scoped to a repetition rule that each -- digest belongs, ordered by created_at timestamp of the digests. -- +migrate Up -UPDATE digests -SET version=t1.version -FROM ( - SELECT - digests.uuid, - ROW_NUMBER() OVER (PARTITION BY digests.rule_id ORDER BY digests.created_at) AS version - FROM digests - WHERE digests.rule_id IS NOT NULL -) AS t1 -WHERE digests.uuid = t1.uuid; -- +migrate Down -UPDATE digests -SET version=0; diff --git a/pkg/server/database/migrations/20191226093447-add-digest-id-primary-key.sql b/pkg/server/database/migrations/20191226093447-add-digest-id-primary-key.sql index febdc4b5..c7d17d2e 100644 --- a/pkg/server/database/migrations/20191226093447-add-digest-id-primary-key.sql +++ b/pkg/server/database/migrations/20191226093447-add-digest-id-primary-key.sql @@ -1,10 +1,5 @@ +-- this migration is noop because digests have been removed -- +migrate Up -ALTER TABLE digests DROP CONSTRAINT digests_pkey; -ALTER TABLE digests ADD PRIMARY KEY (id); - -- +migrate Down - -ALTER TABLE digests DROP CONSTRAINT digests_pkey; -ALTER TABLE digests ADD PRIMARY KEY (uuid); diff --git a/pkg/server/database/migrations/20191226105659-use-id-in-digest-notes-joining-table.sql b/pkg/server/database/migrations/20191226105659-use-id-in-digest-notes-joining-table.sql index 24a45662..faec52ff 100644 --- a/pkg/server/database/migrations/20191226105659-use-id-in-digest-notes-joining-table.sql +++ b/pkg/server/database/migrations/20191226105659-use-id-in-digest-notes-joining-table.sql @@ -1,49 +1,8 @@ +-- this migration is noop because digests have been removed + -- -use-id-in-digest-notes-joining-table.sql replaces uuids with ids -- as foreign keys in the digest_notes joining table. -- +migrate Up -DO $$ - --- +migrate StatementBegin -BEGIN - PERFORM column_name FROM information_schema.columns WHERE table_name= 'digest_notes' and column_name = 'digest_id'; - IF NOT found THEN - ALTER TABLE digest_notes ADD COLUMN digest_id int; - END IF; - PERFORM column_name FROM information_schema.columns WHERE table_name= 'digest_notes' and column_name = 'note_id'; - IF NOT found THEN - ALTER TABLE digest_notes ADD COLUMN note_id int; - END IF; - - -- migrate if digest_notes.digest_uuid exists - PERFORM column_name FROM information_schema.columns WHERE table_name= 'digest_notes' and column_name = 'digest_uuid'; - IF found THEN - -- update note_id - UPDATE digest_notes - SET note_id=t1.note_id - FROM ( - SELECT notes.id AS note_id, notes.uuid AS note_uuid - FROM digest_notes - INNER JOIN notes ON notes.uuid = digest_notes.note_uuid - ) AS t1 - WHERE digest_notes.note_uuid = t1.note_uuid; - - -- update digest_id - UPDATE digest_notes - SET digest_id=t1.digest_id - FROM ( - SELECT digests.id AS digest_id, digests.uuid AS digest_uuid - FROM digest_notes - INNER JOIN digests ON digests.uuid = digest_notes.digest_uuid - ) AS t1 - WHERE digest_notes.digest_uuid = t1.digest_uuid; - - ALTER TABLE digest_notes DROP COLUMN digest_uuid; - ALTER TABLE digest_notes DROP COLUMN note_uuid; - END IF; -END; $$ --- +migrate StatementEnd - - -- +migrate Down diff --git a/pkg/server/database/migrations/20191226152111-delete-outdated-digests.sql b/pkg/server/database/migrations/20191226152111-delete-outdated-digests.sql index 9b093329..84c8ccf3 100644 --- a/pkg/server/database/migrations/20191226152111-delete-outdated-digests.sql +++ b/pkg/server/database/migrations/20191226152111-delete-outdated-digests.sql @@ -1,15 +1,8 @@ +-- this migration is noop because digests have been removed + -- delete-outdated-digests.sql deletes digests that do not belong to any repetition rules, -- along with digest_notes associations. -- +migrate Up -DELETE -FROM digest_notes -USING digests -WHERE - digests.rule_id IS NULL AND - digests.id = digest_notes.digest_id; - -DELETE FROM digests -WHERE digests.rule_id IS NULL; -- +migrate Down