mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Add unique constraint on user_id and name to subscriptions table
This commit is contained in:
parent
892a9ef30d
commit
08e0423939
4 changed files with 16 additions and 3 deletions
|
|
@ -196,12 +196,14 @@ export const createTestLabel = async (
|
|||
|
||||
export const createTestSubscription = async (
|
||||
user: User,
|
||||
name: string
|
||||
name: string,
|
||||
newsletterEmail: NewsletterEmail
|
||||
): Promise<Subscription> => {
|
||||
return getRepository(Subscription).save({
|
||||
user,
|
||||
name,
|
||||
status: SubscriptionStatus.Active,
|
||||
newsletterEmail,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import { Subscription } from '../../src/entity/subscription'
|
|||
import { expect } from 'chai'
|
||||
import 'mocha'
|
||||
import { User } from '../../src/entity/user'
|
||||
import { getRepository } from '../../src/entity/utils'
|
||||
import { NewsletterEmail } from '../../src/entity/newsletter_email'
|
||||
|
||||
describe('Subscriptions API', () => {
|
||||
let user: User
|
||||
|
|
@ -19,9 +21,16 @@ describe('Subscriptions API', () => {
|
|||
|
||||
authToken = res.body.authToken
|
||||
|
||||
// create test newsletter subscriptions
|
||||
const newsletterEmail = await getRepository(NewsletterEmail).save({
|
||||
user,
|
||||
address: 'test@inbox.omnivore.app',
|
||||
confirmationCode: 'test',
|
||||
})
|
||||
|
||||
// create testing subscriptions
|
||||
const sub1 = await createTestSubscription(user, 'sub_1')
|
||||
const sub2 = await createTestSubscription(user, 'sub_2')
|
||||
const sub1 = await createTestSubscription(user, 'sub_1', newsletterEmail)
|
||||
const sub2 = await createTestSubscription(user, 'sub_2', newsletterEmail)
|
||||
subscriptions = [sub2, sub1]
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
BEGIN;
|
||||
|
||||
ALTER TABLE omnivore.subscriptions
|
||||
ADD CONSTRAINT subscriptions_user_id_name_key UNIQUE (user_id, name),
|
||||
ADD COLUMN newsletter_email_id uuid REFERENCES omnivore.newsletter_emails(id);
|
||||
|
||||
-- migrate existing data
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ BEGIN;
|
|||
|
||||
-- remove old column
|
||||
ALTER TABLE omnivore.subscriptions
|
||||
DROP CONSTRAINT subscriptions_user_id_name_key,
|
||||
ADD COLUMN newsletter_email text;
|
||||
|
||||
-- migrate existing data
|
||||
|
|
|
|||
Loading…
Reference in a new issue