Skip to content

Commit 9f9f195

Browse files
committed
refactor: use uuid v7 instead of v4
1 parent 90a3e5f commit 9f9f195

File tree

8 files changed

+34
-35
lines changed

8 files changed

+34
-35
lines changed

Cargo.lock

Lines changed: 10 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ resolver = "2"
88
[package]
99
name = "backend"
1010
description = "Backend API and services for StackClass"
11-
version = "0.39.0"
11+
version = "0.40.0"
1212
edition = "2024"
1313

1414
default-run = "stackclass-server"
@@ -66,4 +66,4 @@ tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
6666
url = "2.5.4"
6767
utoipa = { version = "5.4.0", features = ["axum_extras", "uuid", "chrono", "macros"] }
6868
utoipa-swagger-ui = { version = "9.0.2", features = ["axum", "reqwest"] }
69-
uuid = { version = "1.18.0", features = ["serde", "v4", "fast-rng", "macro-diagnostics"] }
69+
uuid = { version = "1.18.0", features = ["v7", "serde"] }
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- Migration to remove UUID default values since IDs are generated in application code
2+
-- This allows using UUID v7 from the application layer
3+
4+
-- Remove default values from all tables
5+
ALTER TABLE courses ALTER COLUMN id DROP DEFAULT;
6+
ALTER TABLE extensions ALTER COLUMN id DROP DEFAULT;
7+
ALTER TABLE stages ALTER COLUMN id DROP DEFAULT;
8+
ALTER TABLE user_courses ALTER COLUMN id DROP DEFAULT;
9+
ALTER TABLE user_stages ALTER COLUMN id DROP DEFAULT;
10+
11+
-- Drop the uuid-ossp extension since it's no longer needed
12+
DROP EXTENSION IF EXISTS "uuid-ossp";

openapi.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"license": {
77
"name": ""
88
},
9-
"version": "0.39.0"
9+
"version": "0.40.0"
1010
},
1111
"paths": {
1212
"/v1/courses": {

src/model/course.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl CourseModel {
7575
impl From<&Course> for CourseModel {
7676
fn from(course: &Course) -> Self {
7777
Self {
78-
id: Uuid::new_v4(),
78+
id: Uuid::now_v7(),
7979
slug: course.slug.clone(),
8080
name: course.name.clone(),
8181
short_name: course.short_name.clone(),
@@ -134,9 +134,9 @@ pub struct UserCourseModel {
134134
impl Default for UserCourseModel {
135135
fn default() -> Self {
136136
Self {
137-
id: Uuid::new_v4(),
137+
id: Uuid::now_v7(),
138138
user_id: String::new(),
139-
course_id: Uuid::new_v4(),
139+
course_id: Uuid::now_v7(),
140140
course_slug: String::new(),
141141
started_at: Utc::now(),
142142
current_stage_id: None,

src/model/extension.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ impl ExtensionModel {
7272
impl From<Extension> for ExtensionModel {
7373
fn from(ext: Extension) -> Self {
7474
Self {
75-
id: Uuid::new_v4(),
75+
id: Uuid::now_v7(),
7676
// Will be replaced by actual course_id
77-
course_id: Uuid::new_v4(),
77+
course_id: Uuid::now_v7(),
7878
slug: ext.slug,
7979
name: ext.name,
8080
description: ext.description,

src/model/stage.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ impl StageModel {
8585
impl From<Stage> for StageModel {
8686
fn from(stage: Stage) -> Self {
8787
Self {
88-
id: Uuid::new_v4(),
88+
id: Uuid::now_v7(),
8989
// Will be replaced by actual course_id
90-
course_id: Uuid::new_v4(),
90+
course_id: Uuid::now_v7(),
9191
// Will be replaced by actual extension_id
9292
extension_id: None,
9393
extension_slug: None,
@@ -139,7 +139,7 @@ impl UserStageModel {
139139
/// Creates a new instance with default values
140140
pub fn new(user_course_id: Uuid, stage_id: Uuid) -> Self {
141141
Self {
142-
id: Uuid::new_v4(),
142+
id: Uuid::now_v7(),
143143
user_course_id,
144144
course_slug: String::new(),
145145
stage_id,

src/service/pipeline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl PipelineService {
111111

112112
/// Generates a PipelineRun resource for the given repository.
113113
async fn generate(&self, repo: &str, course: &str, stage: &str) -> Result<DynamicObject> {
114-
let name = Uuid::new_v4().to_string();
114+
let name = Uuid::now_v7().to_string();
115115

116116
// Define labels for identification
117117
let labels = vec![

0 commit comments

Comments
 (0)