Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DojoBackendAPI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dojo Project (HES-SO)
Projects
Backend
DojoBackendAPI
Commits
8f30188a
Commit
8f30188a
authored
2 years ago
by
michael.minelli
Browse files
Options
Downloads
Patches
Plain Diff
DB => Add exercice secret field
parent
cf059994
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
ExpressAPI/prisma/migrations/20230725145525_add_exercice_secret/migration.sql
+42
-0
42 additions, 0 deletions
...grations/20230725145525_add_exercice_secret/migration.sql
ExpressAPI/prisma/schema.prisma
+1
-0
1 addition, 0 deletions
ExpressAPI/prisma/schema.prisma
with
43 additions
and
0 deletions
ExpressAPI/prisma/migrations/20230725145525_add_exercice_secret/migration.sql
0 → 100644
+
42
−
0
View file @
8f30188a
/*
Warnings:
- A unique constraint covering the columns `[secret]` on the table `Exercice` will be added. If there are existing duplicate values, this will fail.
- Added the required column `secret` to the `Exercice` table without a default value. This is not possible if the table is not empty.
*/
-- AlterTable
ALTER
TABLE
`Exercice`
ADD
COLUMN
`secret`
CHAR
(
36
)
NOT
NULL
;
-- Add the secret to the existing exercices
-- Source of the function : https://stackoverflow.com/questions/32965743/how-to-generate-a-uuidv4-in-mysql/32965744#32965744
-- Change delimiter so that the function body doesn't end the function declaration
DROP
FUNCTION
IF
EXISTS
uuid_v4
;
CREATE
FUNCTION
uuid_v4
()
RETURNS
CHAR
(
36
)
NO
SQL
BEGIN
-- Generate 8 2-byte strings that we will combine into a UUIDv4
SET
@
h1
=
LPAD
(
HEX
(
FLOOR
(
RAND
()
*
0
xffff
)),
4
,
'0'
);
SET
@
h2
=
LPAD
(
HEX
(
FLOOR
(
RAND
()
*
0
xffff
)),
4
,
'0'
);
SET
@
h3
=
LPAD
(
HEX
(
FLOOR
(
RAND
()
*
0
xffff
)),
4
,
'0'
);
SET
@
h6
=
LPAD
(
HEX
(
FLOOR
(
RAND
()
*
0
xffff
)),
4
,
'0'
);
SET
@
h7
=
LPAD
(
HEX
(
FLOOR
(
RAND
()
*
0
xffff
)),
4
,
'0'
);
SET
@
h8
=
LPAD
(
HEX
(
FLOOR
(
RAND
()
*
0
xffff
)),
4
,
'0'
);
-- 4th section will start with a 4 indicating the version
SET
@
h4
=
CONCAT
(
'4'
,
LPAD
(
HEX
(
FLOOR
(
RAND
()
*
0
x0fff
)),
3
,
'0'
));
-- 5th section first half-byte can only be 8, 9 A or B
SET
@
h5
=
CONCAT
(
HEX
(
FLOOR
(
RAND
()
*
4
+
8
)),
LPAD
(
HEX
(
FLOOR
(
RAND
()
*
0
x0fff
)),
3
,
'0'
));
-- Build the complete UUID
RETURN
LOWER
(
CONCAT
(
@
h1
,
@
h2
,
'-'
,
@
h3
,
'-'
,
@
h4
,
'-'
,
@
h5
,
'-'
,
@
h6
,
@
h7
,
@
h8
));
END
;
UPDATE
`Exercice`
SET
`secret`
=
uuid_v4
();
-- CreateIndex
CREATE
UNIQUE
INDEX
`Exercice_secret_key`
ON
`Exercice`
(
`secret`
);
This diff is collapsed.
Click to expand it.
ExpressAPI/prisma/schema.prisma
+
1
−
0
View file @
8f30188a
...
...
@@ -38,6 +38,7 @@ model Exercice {
id String @id @db.Char(36)
enonceName String
name String
secret String @unique @db.Char(36)
gitlabId Int
gitlabLink String
gitlabCreationInfo Json @db.Json
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment