Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 'users' unique constraints #469

Merged
merged 4 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/org/radarbase/appserver/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
@Table(
name = "users",
uniqueConstraints = {
@UniqueConstraint(columnNames = {"subject_id", "fcm_token", "project_id"})
@UniqueConstraint(columnNames = {"subject_id", "project_id"}),
@UniqueConstraint(columnNames = {"fcm_token"})
})
@Entity
@Getter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public synchronized Map<String, Protocol> fetchProtocols() {
Map<String, Protocol> subjectProtocolMap = users.parallelStream()
.map(u -> this.fetchProtocolForSingleUser(u, u.getProject().getProjectId(), protocolPaths))
.filter(c -> c.getProtocol() != null)
.distinct()
.collect(Collectors.toMap(ProtocolCacheEntry::getId, ProtocolCacheEntry::getProtocol));

log.info("Refreshed Protocols from Github");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
databaseChangeLog:
- changeSet:
id: 1543511610622-8
author: pauline
changes:
- dropUniqueConstraint:
tableName: users
constraintName: UKmm6u3xspqfqoolkjhsvdrqefq
- changeSet:
id: 1716400827373-1
author: pauline
changes:
- addUniqueConstraint:
columnNames: subject_id, project_id
constraintName: UK_subject_project
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can maybe make this a bit more unique to avoid clashes (like adding timestamp at the end or a random string)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes made the changes.

tableName: users
- changeSet:
id: 1716400827373-2
author: pauline
changes:
- addUniqueConstraint:
columnNames: fcm_token
constraintName: UK_fcm_token
tableName: users