Skip to content

Commit 6a7c5b4

Browse files
feat: Allow changing a table id type between int and uuid (serverpod#3299)
1 parent f623194 commit 6a7c5b4

File tree

102 files changed

+37602
-3080
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+37602
-3080
lines changed

packages/serverpod/lib/src/database/concepts/table.dart

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ class Table<T_ID> {
5454
this,
5555
hasDefault: true,
5656
) as ColumnComparable<T_ID>;
57+
} else if (T_ID == UuidValue) {
58+
id = ColumnUuid(
59+
'id',
60+
this,
61+
hasDefault: true,
62+
) as ColumnComparable<T_ID>;
5763
} else {
5864
throw Exception('Unsupported id type: $T_ID');
5965
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* AUTOMATICALLY GENERATED CODE DO NOT MODIFY */
2+
/* To generate run: "serverpod generate" */
3+
4+
// ignore_for_file: implementation_imports
5+
// ignore_for_file: library_private_types_in_public_api
6+
// ignore_for_file: non_constant_identifier_names
7+
// ignore_for_file: public_member_api_docs
8+
// ignore_for_file: type_literal_in_constant_pattern
9+
// ignore_for_file: use_super_parameters
10+
11+
// ignore_for_file: no_leading_underscores_for_library_prefixes
12+
import 'package:serverpod_client/serverpod_client.dart' as _i1;
13+
import 'package:uuid/uuid.dart' as _i2;
14+
import '../../changed_id_type/many_to_many/enrollment.dart' as _i3;
15+
16+
abstract class CourseUuid implements _i1.SerializableModel {
17+
CourseUuid._({
18+
_i1.UuidValue? id,
19+
required this.name,
20+
this.enrollments,
21+
}) : id = id ?? _i2.Uuid().v4obj();
22+
23+
factory CourseUuid({
24+
_i1.UuidValue? id,
25+
required String name,
26+
List<_i3.EnrollmentInt>? enrollments,
27+
}) = _CourseUuidImpl;
28+
29+
factory CourseUuid.fromJson(Map<String, dynamic> jsonSerialization) {
30+
return CourseUuid(
31+
id: jsonSerialization['id'] == null
32+
? null
33+
: _i1.UuidValueJsonExtension.fromJson(jsonSerialization['id']),
34+
name: jsonSerialization['name'] as String,
35+
enrollments: (jsonSerialization['enrollments'] as List?)
36+
?.map((e) => _i3.EnrollmentInt.fromJson((e as Map<String, dynamic>)))
37+
.toList(),
38+
);
39+
}
40+
41+
/// The database id, set if the object has been inserted into the
42+
/// database or if it has been fetched from the database. Otherwise,
43+
/// the id will be null.
44+
_i1.UuidValue? id;
45+
46+
String name;
47+
48+
List<_i3.EnrollmentInt>? enrollments;
49+
50+
/// Returns a shallow copy of this [CourseUuid]
51+
/// with some or all fields replaced by the given arguments.
52+
@_i1.useResult
53+
CourseUuid copyWith({
54+
_i1.UuidValue? id,
55+
String? name,
56+
List<_i3.EnrollmentInt>? enrollments,
57+
});
58+
@override
59+
Map<String, dynamic> toJson() {
60+
return {
61+
if (id != null) 'id': id?.toJson(),
62+
'name': name,
63+
if (enrollments != null)
64+
'enrollments': enrollments?.toJson(valueToJson: (v) => v.toJson()),
65+
};
66+
}
67+
68+
@override
69+
String toString() {
70+
return _i1.SerializationManager.encode(this);
71+
}
72+
}
73+
74+
class _Undefined {}
75+
76+
class _CourseUuidImpl extends CourseUuid {
77+
_CourseUuidImpl({
78+
_i1.UuidValue? id,
79+
required String name,
80+
List<_i3.EnrollmentInt>? enrollments,
81+
}) : super._(
82+
id: id,
83+
name: name,
84+
enrollments: enrollments,
85+
);
86+
87+
/// Returns a shallow copy of this [CourseUuid]
88+
/// with some or all fields replaced by the given arguments.
89+
@_i1.useResult
90+
@override
91+
CourseUuid copyWith({
92+
Object? id = _Undefined,
93+
String? name,
94+
Object? enrollments = _Undefined,
95+
}) {
96+
return CourseUuid(
97+
id: id is _i1.UuidValue? ? id : this.id,
98+
name: name ?? this.name,
99+
enrollments: enrollments is List<_i3.EnrollmentInt>?
100+
? enrollments
101+
: this.enrollments?.map((e0) => e0.copyWith()).toList(),
102+
);
103+
}
104+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/* AUTOMATICALLY GENERATED CODE DO NOT MODIFY */
2+
/* To generate run: "serverpod generate" */
3+
4+
// ignore_for_file: implementation_imports
5+
// ignore_for_file: library_private_types_in_public_api
6+
// ignore_for_file: non_constant_identifier_names
7+
// ignore_for_file: public_member_api_docs
8+
// ignore_for_file: type_literal_in_constant_pattern
9+
// ignore_for_file: use_super_parameters
10+
11+
// ignore_for_file: no_leading_underscores_for_library_prefixes
12+
import 'package:serverpod_client/serverpod_client.dart' as _i1;
13+
import '../../changed_id_type/many_to_many/student.dart' as _i2;
14+
import '../../changed_id_type/many_to_many/course.dart' as _i3;
15+
16+
abstract class EnrollmentInt implements _i1.SerializableModel {
17+
EnrollmentInt._({
18+
this.id,
19+
required this.studentId,
20+
this.student,
21+
required this.courseId,
22+
this.course,
23+
});
24+
25+
factory EnrollmentInt({
26+
int? id,
27+
required _i1.UuidValue studentId,
28+
_i2.StudentUuid? student,
29+
required _i1.UuidValue courseId,
30+
_i3.CourseUuid? course,
31+
}) = _EnrollmentIntImpl;
32+
33+
factory EnrollmentInt.fromJson(Map<String, dynamic> jsonSerialization) {
34+
return EnrollmentInt(
35+
id: jsonSerialization['id'] as int?,
36+
studentId:
37+
_i1.UuidValueJsonExtension.fromJson(jsonSerialization['studentId']),
38+
student: jsonSerialization['student'] == null
39+
? null
40+
: _i2.StudentUuid.fromJson(
41+
(jsonSerialization['student'] as Map<String, dynamic>)),
42+
courseId:
43+
_i1.UuidValueJsonExtension.fromJson(jsonSerialization['courseId']),
44+
course: jsonSerialization['course'] == null
45+
? null
46+
: _i3.CourseUuid.fromJson(
47+
(jsonSerialization['course'] as Map<String, dynamic>)),
48+
);
49+
}
50+
51+
/// The database id, set if the object has been inserted into the
52+
/// database or if it has been fetched from the database. Otherwise,
53+
/// the id will be null.
54+
int? id;
55+
56+
_i1.UuidValue studentId;
57+
58+
_i2.StudentUuid? student;
59+
60+
_i1.UuidValue courseId;
61+
62+
_i3.CourseUuid? course;
63+
64+
/// Returns a shallow copy of this [EnrollmentInt]
65+
/// with some or all fields replaced by the given arguments.
66+
@_i1.useResult
67+
EnrollmentInt copyWith({
68+
int? id,
69+
_i1.UuidValue? studentId,
70+
_i2.StudentUuid? student,
71+
_i1.UuidValue? courseId,
72+
_i3.CourseUuid? course,
73+
});
74+
@override
75+
Map<String, dynamic> toJson() {
76+
return {
77+
if (id != null) 'id': id,
78+
'studentId': studentId.toJson(),
79+
if (student != null) 'student': student?.toJson(),
80+
'courseId': courseId.toJson(),
81+
if (course != null) 'course': course?.toJson(),
82+
};
83+
}
84+
85+
@override
86+
String toString() {
87+
return _i1.SerializationManager.encode(this);
88+
}
89+
}
90+
91+
class _Undefined {}
92+
93+
class _EnrollmentIntImpl extends EnrollmentInt {
94+
_EnrollmentIntImpl({
95+
int? id,
96+
required _i1.UuidValue studentId,
97+
_i2.StudentUuid? student,
98+
required _i1.UuidValue courseId,
99+
_i3.CourseUuid? course,
100+
}) : super._(
101+
id: id,
102+
studentId: studentId,
103+
student: student,
104+
courseId: courseId,
105+
course: course,
106+
);
107+
108+
/// Returns a shallow copy of this [EnrollmentInt]
109+
/// with some or all fields replaced by the given arguments.
110+
@_i1.useResult
111+
@override
112+
EnrollmentInt copyWith({
113+
Object? id = _Undefined,
114+
_i1.UuidValue? studentId,
115+
Object? student = _Undefined,
116+
_i1.UuidValue? courseId,
117+
Object? course = _Undefined,
118+
}) {
119+
return EnrollmentInt(
120+
id: id is int? ? id : this.id,
121+
studentId: studentId ?? this.studentId,
122+
student: student is _i2.StudentUuid? ? student : this.student?.copyWith(),
123+
courseId: courseId ?? this.courseId,
124+
course: course is _i3.CourseUuid? ? course : this.course?.copyWith(),
125+
);
126+
}
127+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* AUTOMATICALLY GENERATED CODE DO NOT MODIFY */
2+
/* To generate run: "serverpod generate" */
3+
4+
// ignore_for_file: implementation_imports
5+
// ignore_for_file: library_private_types_in_public_api
6+
// ignore_for_file: non_constant_identifier_names
7+
// ignore_for_file: public_member_api_docs
8+
// ignore_for_file: type_literal_in_constant_pattern
9+
// ignore_for_file: use_super_parameters
10+
11+
// ignore_for_file: no_leading_underscores_for_library_prefixes
12+
import 'package:serverpod_client/serverpod_client.dart' as _i1;
13+
import 'package:uuid/uuid.dart' as _i2;
14+
import '../../changed_id_type/many_to_many/enrollment.dart' as _i3;
15+
16+
abstract class StudentUuid implements _i1.SerializableModel {
17+
StudentUuid._({
18+
_i1.UuidValue? id,
19+
required this.name,
20+
this.enrollments,
21+
}) : id = id ?? _i2.Uuid().v4obj();
22+
23+
factory StudentUuid({
24+
_i1.UuidValue? id,
25+
required String name,
26+
List<_i3.EnrollmentInt>? enrollments,
27+
}) = _StudentUuidImpl;
28+
29+
factory StudentUuid.fromJson(Map<String, dynamic> jsonSerialization) {
30+
return StudentUuid(
31+
id: jsonSerialization['id'] == null
32+
? null
33+
: _i1.UuidValueJsonExtension.fromJson(jsonSerialization['id']),
34+
name: jsonSerialization['name'] as String,
35+
enrollments: (jsonSerialization['enrollments'] as List?)
36+
?.map((e) => _i3.EnrollmentInt.fromJson((e as Map<String, dynamic>)))
37+
.toList(),
38+
);
39+
}
40+
41+
/// The database id, set if the object has been inserted into the
42+
/// database or if it has been fetched from the database. Otherwise,
43+
/// the id will be null.
44+
_i1.UuidValue? id;
45+
46+
String name;
47+
48+
List<_i3.EnrollmentInt>? enrollments;
49+
50+
/// Returns a shallow copy of this [StudentUuid]
51+
/// with some or all fields replaced by the given arguments.
52+
@_i1.useResult
53+
StudentUuid copyWith({
54+
_i1.UuidValue? id,
55+
String? name,
56+
List<_i3.EnrollmentInt>? enrollments,
57+
});
58+
@override
59+
Map<String, dynamic> toJson() {
60+
return {
61+
if (id != null) 'id': id?.toJson(),
62+
'name': name,
63+
if (enrollments != null)
64+
'enrollments': enrollments?.toJson(valueToJson: (v) => v.toJson()),
65+
};
66+
}
67+
68+
@override
69+
String toString() {
70+
return _i1.SerializationManager.encode(this);
71+
}
72+
}
73+
74+
class _Undefined {}
75+
76+
class _StudentUuidImpl extends StudentUuid {
77+
_StudentUuidImpl({
78+
_i1.UuidValue? id,
79+
required String name,
80+
List<_i3.EnrollmentInt>? enrollments,
81+
}) : super._(
82+
id: id,
83+
name: name,
84+
enrollments: enrollments,
85+
);
86+
87+
/// Returns a shallow copy of this [StudentUuid]
88+
/// with some or all fields replaced by the given arguments.
89+
@_i1.useResult
90+
@override
91+
StudentUuid copyWith({
92+
Object? id = _Undefined,
93+
String? name,
94+
Object? enrollments = _Undefined,
95+
}) {
96+
return StudentUuid(
97+
id: id is _i1.UuidValue? ? id : this.id,
98+
name: name ?? this.name,
99+
enrollments: enrollments is List<_i3.EnrollmentInt>?
100+
? enrollments
101+
: this.enrollments?.map((e0) => e0.copyWith()).toList(),
102+
);
103+
}
104+
}

0 commit comments

Comments
 (0)