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

Referential actions in the Prisma Schema Language #1947

Merged
merged 57 commits into from Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
619733a
Referential action support for IE, ME and PSL
May 20, 2021
18ac766
Do not render default referential actions
Jun 2, 2021
feef5f3
Remove legacy cascades.
dpetrick Jun 4, 2021
d4b9fc0
Emulated actions
Jun 7, 2021
efa606e
First pass over the graph
dpetrick Jun 7, 2021
28634ef
Merge branch 'referential-actions' into query-engine/referential_actions
dpetrick Jun 7, 2021
e6f8c48
Experiments with deletion checks.
dpetrick Jun 7, 2021
1f3bc2c
Default virtual actions
Jun 7, 2021
9e6ea45
Working db propagation.
dpetrick Jun 7, 2021
a4032c5
Add new prisma-fmt command referential-actions
Jun 7, 2021
4f4f04f
Get the default actions from dml (if possible)
Jun 8, 2021
7bef40a
onUpdate should always CASCADE.
Jun 8, 2021
ecf9b5b
Minor schema fix for update
dpetrick Jun 9, 2021
7eaaaf0
Core graph debugging
dpetrick Jun 9, 2021
a73614f
Merge branch 'referential-actions' into query-engine/referential_actions
dpetrick Jun 9, 2021
4054aba
Merge branch 'master' into referential-actions
Jun 9, 2021
af5b0fa
Merge branch 'referential-actions' into query-engine/referential_actions
dpetrick Jun 9, 2021
eb2ff28
Emulation defaults
dpetrick Jun 9, 2021
bf26779
No virtuals, foreign key capability, validations
Jun 11, 2021
486e285
Add test for onUpdate on the wrong side
Jun 11, 2021
40cd6b2
First tests for onDelete
dpetrick Jun 11, 2021
a824868
Missing onDelete mode tests
dpetrick Jun 14, 2021
b7d7858
Merge branch 'referential-actions' into query-engine/referential_actions
dpetrick Jun 14, 2021
63f2fa8
Disable emulation correctly.
dpetrick Jun 14, 2021
ae2f024
Clippy.
dpetrick Jun 14, 2021
912d03b
Fix test_suite macro
dpetrick Jun 14, 2021
74b9cd8
Ignore SetDefault for MySQL
dpetrick Jun 14, 2021
21308fb
More nuanced restrict emulation
dpetrick Jun 15, 2021
065e991
Skeleton work
dpetrick Jun 16, 2021
a28c9ef
Feature-gating referential actions for IE/ME
Jun 15, 2021
15acaff
Implement onDelete cascades emulation.
dpetrick Jun 17, 2021
da6661d
Clippy.
dpetrick Jun 17, 2021
00ec7c1
Add cascade onUpdate spec
dpetrick Jun 17, 2021
b0b337a
Green IE/PSL tests
Jun 18, 2021
adcc20b
WIP: Fixing ME tests
Jun 18, 2021
2d8e33f
onUpdate tests
dpetrick Jun 18, 2021
f93151a
Merge branch 'referential-actions' of github.com:prisma/prisma-engine…
dpetrick Jun 18, 2021
4b1bbff
Setting up
dpetrick Jun 19, 2021
3c4c400
Add preview_features test params for ME
Jun 21, 2021
06c16b2
onUpdate work.
dpetrick Jun 21, 2021
d3f0ee4
Merge branch 'query-engine/referential_actions_emulation_v2' into ref…
dpetrick Jun 21, 2021
ea7a010
Compilation
dpetrick Jun 21, 2021
0ba0965
Merge branch 'master' into referential-actions
Jun 21, 2021
68badc9
IE/ME clippy
Jun 21, 2021
357ce5c
Do not patch barrel
Jun 21, 2021
67a4939
More clippy
Jun 21, 2021
d526152
Make legacy compound defaults work again
Jun 21, 2021
7931c4c
Set referential action for compounds correctly
Jun 22, 2021
1926d49
Merge branch 'master' into referential-actions
Jun 22, 2021
b5bd2f1
Nyeh nyeh test fix
Jun 22, 2021
d1b654c
LAST BROKEN TESTS
Jun 22, 2021
ed65a0e
LAST LAST BROKEN TESTS
Jun 22, 2021
1cc068d
Merge branch 'master' into referential-actions
Jun 22, 2021
de24f6b
First round of review fixes
Jun 22, 2021
288f969
Rename variable
Jun 22, 2021
ea849b2
Clone -> cloned
Jun 22, 2021
de3b045
Validation error if ref actions on both sides
Jun 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .envrc
@@ -1,11 +1,11 @@
export SERVER_ROOT=$(pwd)
export RUST_LOG_FORMAT=devel
export RUST_BACKTRACE=1
export RUST_LOG=query_engine=debug,query_core=trace,query_connector=debug,sql_query_connector=debug,prisma_models=debug,engineer=info,sql_introspection_connector=debug
export RUST_LOG=query_engine_tests=trace,query_engine=debug,query_core=trace,query_connector=debug,sql_query_connector=debug,prisma_models=debug,engineer=info,sql_introspection_connector=debug
export SKIP_CONNECTORS="vitess_5_7,vitess_8_0"

# Controls Scala test kit verbosity. Levels are trace, debug, info, error, warning
export LOG_LEVEL=debug
export LOG_LEVEL=trace

# Controls Scala test kit test complexity ("simple", "complex")
export TEST_MODE=simple
Expand Down
9 changes: 7 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

121 changes: 23 additions & 98 deletions datamodel_v2.prisma
@@ -1,115 +1,40 @@
datasource chinook {
provider = "sqlite"
url = "file:./db/Chinook.db?connection_limit=1&socket_timeout=20"
datasource db {
provider = "postgres"
url = "postgresql://postgres:prisma@localhost:5432"
}

generator js {
provider = "prisma-client-js"
previewFeatures = ["microsoftSqlServer", "mongodb", "orderByRelation", "napi", "selectRelationCount", "orderByAggregateGroup"]
previewFeatures = ["microsoftSqlServer", "mongodb", "orderByRelation", "napi", "selectRelationCount", "orderByAggregateGroup", "referentialActions"]
}

model Album {
id Int @id @map("AlbumId")
Title String @default("TestDefaultTitle")
ArtistId Int
Tracks Track[]
Artist Artist @relation(fields: [ArtistId], references: [id])
}

model Track {
id Int @id @map("TrackId")
Name String
Composer String?
Milliseconds Int
UnitPrice Float
AlbumId Int?
GenreId Int?
MediaTypeId Int
MediaType MediaType @relation(fields: [MediaTypeId], references: [id])
Genre Genre? @relation(fields: [GenreId], references: [id])
Album Album? @relation(fields: [AlbumId], references: [id])
InvoiceLines InvoiceLine[]
}

model MediaType {
id Int @id @map("MediaTypeId")
Name String?
Track Track[]
}
model A {
id String @id
gql String?

model Genre {
id Int @id @map("GenreId")
Name String?
Tracks Track[]
}
bs B[]

model Artist {
id Int @id @map("ArtistId")
Name String?
Albums Album[]
c_id String
c C @relation(fields: [c_id], onDelete: Cascade, references: [id])
}

model Customer {
id Int @id @map("CustomerId")
FirstName String
LastName String
Company String?
Address String?
City String?
State String?
Country String?
PostalCode String?
Phone String?
Fax String?
Email String
SupportRepId Int?
SupportRep Employee? @relation(fields: [SupportRepId], references: [id])
Invoices Invoice[]
}
model B {
id String @id
gql String?

model Employee {
id Int @id @map("EmployeeId")
FirstName String
LastName String
Title String?
BirthDate DateTime?
HireDate DateTime?
Address String?
City String?
State String?
Country String?
PostalCode String?
Phone String?
Fax String?
Email String?
Customers Customer[]
a_id String
a A @relation(fields: [a_id], references: [id], onDelete: Cascade)
}

model Invoice {
id Int @id @map("InvoiceId")
InvoiceDate DateTime
BillingAddress String?
BillingCity String?
BillingState String?
BillingCountry String?
BillingPostalCode String?
Total Float
CustomerId Int
Customer Customer @relation(fields: [CustomerId], references: [id])
Lines InvoiceLine[]
}
model C {
id String @id
gql String?
ds D[] @relation(onDelete: Cascade)

model InvoiceLine {
id Int @id @map("InvoiceLineId")
UnitPrice Float
Quantity Int
InvoiceId Int
TrackId Int
Invoice Invoice @relation(fields: [InvoiceId], references: [id])
Track Track @relation(fields: [TrackId], references: [id])
a A?
}

model Playlist {
id Int @id @map("PlaylistId")
Name String?
model D {
id String @id
cs C[]
}
@@ -1,11 +1,10 @@
use crate::commenting_out_guardrails::commenting_out_guardrails;
use crate::introspection::introspect;
use crate::introspection_helpers::*;
use crate::prisma_1_defaults::*;
use crate::re_introspection::enrich;
use crate::sanitize_datamodel_names::{sanitization_leads_to_duplicate_names, sanitize_datamodel_names};
use crate::version_checker::VersionChecker;
use crate::SqlIntrospectionResult;
use crate::{commenting_out_guardrails::commenting_out_guardrails, introspection::introspect};
use datamodel::Datamodel;
use introspection_connector::IntrospectionResult;
use quaint::connector::SqlFamily;
Expand Down Expand Up @@ -63,7 +62,7 @@ mod tests {
use super::*;
use datamodel::{
dml, Datamodel, DefaultValue as DMLDefault, Field, FieldArity, FieldType, Model, NativeTypeInstance,
OnDeleteStrategy, RelationField, RelationInfo, ScalarField, ScalarType, ValueGenerator,
ReferentialAction, RelationField, RelationInfo, ScalarField, ScalarType, ValueGenerator,
};
use native_types::{NativeType, PostgresType};
use pretty_assertions::assert_eq;
Expand Down Expand Up @@ -470,12 +469,15 @@ mod tests {
Field::RelationField(RelationField::new(
"User",
FieldArity::List,
FieldArity::List,
RelationInfo {
to: "User".to_string(),
fields: vec![],
references: vec![],
name: "CityToUser".to_string(),
on_delete: OnDeleteStrategy::None,
on_delete: None,
on_update: None,
legacy_referential_actions: false,
},
)),
],
Expand Down Expand Up @@ -557,17 +559,26 @@ mod tests {
is_commented_out: false,
is_ignored: false,
}),
Field::RelationField(RelationField::new(
"City",
FieldArity::Required,
RelationInfo {
Field::RelationField(RelationField {
name: "City".into(),
arity: FieldArity::Required,
referential_arity: FieldArity::Required,
documentation: None,
is_generated: false,
is_commented_out: false,
is_ignored: false,
supports_restrict_action: Some(true),
virtual_referential_actions: None,
relation_info: RelationInfo {
name: "CityToUser".to_string(),
to: "City".to_string(),
fields: vec!["city_id".to_string(), "city_name".to_string()],
references: vec!["id".to_string(), "name".to_string()],
on_delete: OnDeleteStrategy::None,
on_delete: Some(ReferentialAction::NoAction),
on_update: Some(ReferentialAction::NoAction),
legacy_referential_actions: false,
},
)),
}),
],
is_generated: false,
indices: vec![],
Expand Down Expand Up @@ -862,12 +873,15 @@ mod tests {
Field::RelationField(RelationField::new(
"User",
FieldArity::List,
FieldArity::List,
RelationInfo {
to: "User".to_string(),
fields: vec![],
references: vec![],
name: "CityToUser".to_string(),
on_delete: OnDeleteStrategy::None,
on_delete: None,
on_update: None,
legacy_referential_actions: false,
},
)),
],
Expand Down Expand Up @@ -918,17 +932,26 @@ mod tests {
}),
),
)),
Field::RelationField(RelationField::new(
"City",
FieldArity::Required,
RelationInfo {
Field::RelationField(RelationField {
name: "City".into(),
arity: FieldArity::Required,
referential_arity: FieldArity::Required,
documentation: None,
is_generated: false,
is_commented_out: false,
is_ignored: false,
supports_restrict_action: Some(true),
virtual_referential_actions: None,
relation_info: RelationInfo {
name: "CityToUser".to_string(),
to: "City".to_string(),
fields: vec!["city_id".to_string()],
references: vec!["id".to_string()],
on_delete: OnDeleteStrategy::None,
on_delete: Some(ReferentialAction::NoAction),
on_update: Some(ReferentialAction::NoAction),
legacy_referential_actions: false,
},
)),
}),
],
is_generated: false,
indices: vec![],
Expand Down
Expand Up @@ -41,7 +41,11 @@ pub fn introspect(
for foreign_key in &foreign_keys_copy {
version_check.has_inline_relations(table);
version_check.uses_on_delete(foreign_key, table);
let relation_field = calculate_relation_field(schema, table, foreign_key)?;

let mut relation_field = calculate_relation_field(schema, table, foreign_key)?;

relation_field.supports_restrict_action(!sql_family.is_mssql());

model.add_field(Field::RelationField(relation_field));
}

Expand Down