Fix rules (#438)

* Fix network

* Fix migrations for table that no longer exist

* Document changed behavior
This commit is contained in:
Sung Won Cho 2020-03-29 09:43:42 +11:00 committed by GitHub
commit 6e690ea4da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 22 additions and 111 deletions

View file

@ -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

View file

@ -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

View file

@ -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" .

View file

@ -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:

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -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

View file

@ -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