SlideShare a Scribd company logo
1 of 26
Download to read offline
&
Rust ORM
Migrations
2
ORM: Benefits
●
Database vendor abstraction
– Developers don’t need to know
the intricacies of the database
●
Multiple database support
●
Auto-generation of migrations
Rust ORM
3
ORM: Benefits
●
Column safety
●
Type safety
●
Foundation of MVC, and any
other architectural pattern
that has a “model”
Rust ORM
4
ORM: Negatives
●
Another leaky abstraction
●
Another dependency
– Bugs, nuances, security issues
●
Another thing to learn
Rust ORM
5
ORM: Gold standard
●
Django - 107 years of effort (COCOMO) – 17 years
old
●
Ruby on Rails – 104 years of effort - 18 years old
– Grails (Groovy) – 205 years of effort – 18 years old
●
Meteor-js - 59 years of effort – 11 years old
●
Symfony - 284 years of effort – 17 years old
●
Hibernate – 230 years of effort – 21 years old
6
ORM: Older products
●
Drupal - 22 years old
●
ASP.NET – 20 years old
●
J2EE
– c.f. Hibernate
– Enterprise JavaBeans – 25 years old
●
WebObjects – 1996-2008 – 12 years
7
Rust ORM: schema crate
●
Create a separate crate with the schema
– OpenAPI/JSONSchema definitions
– Rust struct’s generated by progenitor, including
serialisation/deserialisation functionality
●
Due to Rust’s trait impl coherence rules,
database persistence needs to be added to
these structs
●
Generate for other languages such as
TypeScript
8
Rust ORM: Must have
●
DQL & DML
– Insert, for all data-types used in the schema
– Update, …
– Query, …
●
Actively maintained
●
Transaction support
9
Rust ORM: Nice to have
●
Upsert
– More efficient than alt.: query+insert+update
●
PostgreSQL support
●
Sqlite support
– Very handy for light-weight tests
●
DDL/Migration management
– Another tool can be used for this
10
Rust ORMs: Popular (>1k*)
●
Diesel - 18 years of effort – 8 years old
●
Sea-ORM – 9 years of effort – 2 years old
●
Rbatis – 7 years of effort – 3 years old
Rust database framework
●
sqlx - 2 years of effort – 10 years old
11
Rust ORMs: Obscure
●
Ormx – 1 year of effort – 2.5 years old
●
Rustorm – 2 years of effort – 5 years old - abandoned
●
toql - 5 years of effort – 3 years old
●
Summer-mybatis – 4 years of effort – 1 year old
●
butane - 2 years of effort – 3.5 years old
●
sprattus – 1 years of effort – 2 years old
●
Yukino-dev - 2 years of effort – 2 years old
●
Ormlite – 1 year of effort – 1 year old
●
Tql - 2 years of effort - 7 years old
NoSQL ORMs
●
wither (mongo) - 1 year of effort – 5 years old
12
Rust ORM: diesel
use diesel::prelude::*;
#[derive(Queryable)]
pub struct Post {
pub id: i32,
pub title: String,
pub body: String,
pub published: bool,
}
Add derives … looks simple
13
Rust ORM: diesel
diesel::table! {
posts (id) {
id -> Int4,
title -> Varchar,
body -> Text,
published -> Bool,
}
}
Except diesel needs a “schema.rs” that
defines the database fields for one database
Maybe can be generated by diesel API, and injected
using progenitor’s “post” hook.
14
Rust ORM: Sea-ORM
#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel,
Deserialize, Serialize)]
#[sea_orm(table_name = "posts")]
pub struct Model {
#[sea_orm(primary_key)]
#[serde(skip_deserializing)]
pub id: i32,
pub title: String,
#[sea_orm(column_type = "Text")]
pub text: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}
Every model must be called Model
15
Rust ORM: butane
#[model]
#[derive(Clone, Debug, Default, Deserialize, PartialEq,
Serialize, ToSchema)]
pub struct Blog {
#[serde(default)]
pub posts: Many<Post>,
#[pk]
pub blog_id: uuid::Uuid,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub slug: Option<String>,
}
Requires primary keys, and relations
Vec → Many
16
Migrations: Benefits
●
Rollback
Migrations
17
Migrations: Benefits
●
Rollback
Migrations: Negatives
●
More effort than deleting and
installing schema each deploy...
i.e. there are no negatives
Migrations
18
Migrations: Must have
●
Schema version stored in
each database instance
Migrations
19
Migrations: Must have after v1
●
Migration batch support
– After v1 of any project, new versions
of a product will be released at
intervals that include many schema
changes that were part of different
pull requests
Migrations
20
Migrations: Nice to have
●
Per-change undo
– Mostly used by developers when:
●
Switching branches
●
Developing migrations
– Developers can manually undo
changes
Migrations
21
Migrations: Nice to have
●
Rollback
– Alternative is use backup and
restore
Migrations
22
Migrations: Nice to have
●
Zero-downtime migrations
– Avoid locking
– Schema changes have three phases
1) Additive changes
2) Update services
3) Either
1) Rollback if services stable, or
2) Destructive changes to the schema
Migrations
23
Migrations: Nice to have
●
ORM integration
– Allows database vendor agnostic
migrations
– Allows auto-generating migrations
from model changes
Migrations
24
Rust Migration
●
Reshape - 2 year of effort – 1 year old
– Ticks most boxes, except no ORM integration, and PG only
●
prisma-engines – 65 year of effort – 3 years old
– TypeScript CLI
●
Refinery
– lacks undo features
25
TypeScript Migration
●
prisma – 29 years of effort – 2 years old
●
knex - 20 years of effort – 10 years old
●
Typeorm - 50 years of effort – 6 years old
26
Go Migration
●
Altas – 24 years of effort – 2 years old
●
bytebase - 41 years of effort – 2 years old

More Related Content

Similar to Rust ORMs and Migrations

Hpc to OpenStack: Our journey
Hpc to OpenStack: Our journeyHpc to OpenStack: Our journey
Hpc to OpenStack: Our journeyArif Ali
 
OpenStack Cinder On-Boarding Room - Vancouver Summit 2018
OpenStack Cinder On-Boarding Room - Vancouver Summit 2018OpenStack Cinder On-Boarding Room - Vancouver Summit 2018
OpenStack Cinder On-Boarding Room - Vancouver Summit 2018Jay Bryant
 
Cinder On-boarding Room - Berlin (11-13-2018)
Cinder On-boarding Room - Berlin (11-13-2018)Cinder On-boarding Room - Berlin (11-13-2018)
Cinder On-boarding Room - Berlin (11-13-2018)Jay Bryant
 
Deployments with rails
Deployments with railsDeployments with rails
Deployments with railsGourav Tiwari
 
Tips For Maintaining OSS Projects
Tips For Maintaining OSS ProjectsTips For Maintaining OSS Projects
Tips For Maintaining OSS ProjectsTaro L. Saito
 
Middleware as Code with mruby
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mrubyHiroshi SHIBATA
 
Building OpenStreetMap.org, SOTM US 2015
Building OpenStreetMap.org, SOTM US 2015Building OpenStreetMap.org, SOTM US 2015
Building OpenStreetMap.org, SOTM US 2015Tom Hughes
 
Apache Camel K - Copenhagen v2
Apache Camel K - Copenhagen v2Apache Camel K - Copenhagen v2
Apache Camel K - Copenhagen v2Claus Ibsen
 
Apache Camel K - Copenhagen
Apache Camel K - CopenhagenApache Camel K - Copenhagen
Apache Camel K - CopenhagenClaus Ibsen
 
OpenStack Cinder On-Boarding Education - Boston Summit - 2017
OpenStack Cinder On-Boarding Education - Boston Summit - 2017OpenStack Cinder On-Boarding Education - Boston Summit - 2017
OpenStack Cinder On-Boarding Education - Boston Summit - 2017Jay Bryant
 
Quick introduction to Angular 4 for AngularJS 1.5 developers
Quick introduction to Angular 4 for AngularJS 1.5 developersQuick introduction to Angular 4 for AngularJS 1.5 developers
Quick introduction to Angular 4 for AngularJS 1.5 developersPaweł Żurowski
 
MySQL Workbench and Visual Explain -- RMUG Feb 19th 2015
MySQL Workbench and Visual Explain -- RMUG Feb 19th 2015MySQL Workbench and Visual Explain -- RMUG Feb 19th 2015
MySQL Workbench and Visual Explain -- RMUG Feb 19th 2015Dave Stokes
 
Rails automatic test driven development
Rails automatic test driven developmentRails automatic test driven development
Rails automatic test driven developmenttyler4long
 
Groovy In the Cloud
Groovy In the CloudGroovy In the Cloud
Groovy In the CloudJim Driscoll
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby TeamArto Artnik
 
Functional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdfFunctional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdfssusercd195b
 
Использование AzureDevOps при разработке микросервисных приложений
Использование AzureDevOps при разработке микросервисных приложенийИспользование AzureDevOps при разработке микросервисных приложений
Использование AzureDevOps при разработке микросервисных приложенийVitebsk Miniq
 

Similar to Rust ORMs and Migrations (20)

Hpc to OpenStack: Our journey
Hpc to OpenStack: Our journeyHpc to OpenStack: Our journey
Hpc to OpenStack: Our journey
 
01 - Git vs SVN
01 - Git vs SVN01 - Git vs SVN
01 - Git vs SVN
 
OpenStack Cinder On-Boarding Room - Vancouver Summit 2018
OpenStack Cinder On-Boarding Room - Vancouver Summit 2018OpenStack Cinder On-Boarding Room - Vancouver Summit 2018
OpenStack Cinder On-Boarding Room - Vancouver Summit 2018
 
Cinder On-boarding Room - Berlin (11-13-2018)
Cinder On-boarding Room - Berlin (11-13-2018)Cinder On-boarding Room - Berlin (11-13-2018)
Cinder On-boarding Room - Berlin (11-13-2018)
 
Deployments with rails
Deployments with railsDeployments with rails
Deployments with rails
 
Tips For Maintaining OSS Projects
Tips For Maintaining OSS ProjectsTips For Maintaining OSS Projects
Tips For Maintaining OSS Projects
 
Middleware as Code with mruby
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mruby
 
Building OpenStreetMap.org, SOTM US 2015
Building OpenStreetMap.org, SOTM US 2015Building OpenStreetMap.org, SOTM US 2015
Building OpenStreetMap.org, SOTM US 2015
 
Apache Camel K - Copenhagen v2
Apache Camel K - Copenhagen v2Apache Camel K - Copenhagen v2
Apache Camel K - Copenhagen v2
 
Apache Camel K - Copenhagen
Apache Camel K - CopenhagenApache Camel K - Copenhagen
Apache Camel K - Copenhagen
 
OpenStack Cinder On-Boarding Education - Boston Summit - 2017
OpenStack Cinder On-Boarding Education - Boston Summit - 2017OpenStack Cinder On-Boarding Education - Boston Summit - 2017
OpenStack Cinder On-Boarding Education - Boston Summit - 2017
 
Quick introduction to Angular 4 for AngularJS 1.5 developers
Quick introduction to Angular 4 for AngularJS 1.5 developersQuick introduction to Angular 4 for AngularJS 1.5 developers
Quick introduction to Angular 4 for AngularJS 1.5 developers
 
mtl_rubykaigi
mtl_rubykaigimtl_rubykaigi
mtl_rubykaigi
 
Rails data migrations
Rails data migrationsRails data migrations
Rails data migrations
 
MySQL Workbench and Visual Explain -- RMUG Feb 19th 2015
MySQL Workbench and Visual Explain -- RMUG Feb 19th 2015MySQL Workbench and Visual Explain -- RMUG Feb 19th 2015
MySQL Workbench and Visual Explain -- RMUG Feb 19th 2015
 
Rails automatic test driven development
Rails automatic test driven developmentRails automatic test driven development
Rails automatic test driven development
 
Groovy In the Cloud
Groovy In the CloudGroovy In the Cloud
Groovy In the Cloud
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby Team
 
Functional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdfFunctional Scala 2022 - scalajs Alexis.pdf
Functional Scala 2022 - scalajs Alexis.pdf
 
Использование AzureDevOps при разработке микросервисных приложений
Использование AzureDevOps при разработке микросервисных приложенийИспользование AzureDevOps при разработке микросервисных приложений
Использование AzureDevOps при разработке микросервисных приложений
 

More from John Vandenberg

Rust & Python : Python WA October meetup
Rust & Python : Python WA October meetupRust & Python : Python WA October meetup
Rust & Python : Python WA October meetupJohn Vandenberg
 
Rust & Python : Rust WA meetup 1
Rust & Python : Rust WA meetup 1Rust & Python : Rust WA meetup 1
Rust & Python : Rust WA meetup 1John Vandenberg
 
Besut Kode seminar Lampung
Besut Kode seminar LampungBesut Kode seminar Lampung
Besut Kode seminar LampungJohn Vandenberg
 
Besut Kode Seminar Malang
Besut Kode Seminar MalangBesut Kode Seminar Malang
Besut Kode Seminar MalangJohn Vandenberg
 
Wikimedia indigenous voices
Wikimedia indigenous voicesWikimedia indigenous voices
Wikimedia indigenous voicesJohn Vandenberg
 
SGU - Creating an English Wikipedia draft
SGU - Creating an English Wikipedia draftSGU - Creating an English Wikipedia draft
SGU - Creating an English Wikipedia draftJohn Vandenberg
 
SGU Wikimedia in Education overview
SGU Wikimedia in Education overviewSGU Wikimedia in Education overview
SGU Wikimedia in Education overviewJohn Vandenberg
 
SLQ Wikipedia workshop: creating a draft
SLQ Wikipedia workshop: creating a draftSLQ Wikipedia workshop: creating a draft
SLQ Wikipedia workshop: creating a draftJohn Vandenberg
 
Intelligent info 2012 wikipedia
Intelligent info 2012 wikipediaIntelligent info 2012 wikipedia
Intelligent info 2012 wikipediaJohn Vandenberg
 

More from John Vandenberg (14)

syn
synsyn
syn
 
Rust & Python : Python WA October meetup
Rust & Python : Python WA October meetupRust & Python : Python WA October meetup
Rust & Python : Python WA October meetup
 
Rust & Python : Rust WA meetup 1
Rust & Python : Rust WA meetup 1Rust & Python : Rust WA meetup 1
Rust & Python : Rust WA meetup 1
 
Besut Kode seminar Lampung
Besut Kode seminar LampungBesut Kode seminar Lampung
Besut Kode seminar Lampung
 
Besut Kode Seminar Malang
Besut Kode Seminar MalangBesut Kode Seminar Malang
Besut Kode Seminar Malang
 
Besut Kode - Workshop 2
Besut Kode - Workshop 2Besut Kode - Workshop 2
Besut Kode - Workshop 2
 
Besut Kode - Workshop 1
Besut Kode - Workshop 1Besut Kode - Workshop 1
Besut Kode - Workshop 1
 
Besut Kode Challenge 1
Besut Kode Challenge 1Besut Kode Challenge 1
Besut Kode Challenge 1
 
Wikimedia indigenous voices
Wikimedia indigenous voicesWikimedia indigenous voices
Wikimedia indigenous voices
 
SGU - Creating an English Wikipedia draft
SGU - Creating an English Wikipedia draftSGU - Creating an English Wikipedia draft
SGU - Creating an English Wikipedia draft
 
SGU Wikimedia in Education overview
SGU Wikimedia in Education overviewSGU Wikimedia in Education overview
SGU Wikimedia in Education overview
 
Commons
CommonsCommons
Commons
 
SLQ Wikipedia workshop: creating a draft
SLQ Wikipedia workshop: creating a draftSLQ Wikipedia workshop: creating a draft
SLQ Wikipedia workshop: creating a draft
 
Intelligent info 2012 wikipedia
Intelligent info 2012 wikipediaIntelligent info 2012 wikipedia
Intelligent info 2012 wikipedia
 

Recently uploaded

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Recently uploaded (20)

Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

Rust ORMs and Migrations

  • 2. 2 ORM: Benefits ● Database vendor abstraction – Developers don’t need to know the intricacies of the database ● Multiple database support ● Auto-generation of migrations Rust ORM
  • 3. 3 ORM: Benefits ● Column safety ● Type safety ● Foundation of MVC, and any other architectural pattern that has a “model” Rust ORM
  • 4. 4 ORM: Negatives ● Another leaky abstraction ● Another dependency – Bugs, nuances, security issues ● Another thing to learn Rust ORM
  • 5. 5 ORM: Gold standard ● Django - 107 years of effort (COCOMO) – 17 years old ● Ruby on Rails – 104 years of effort - 18 years old – Grails (Groovy) – 205 years of effort – 18 years old ● Meteor-js - 59 years of effort – 11 years old ● Symfony - 284 years of effort – 17 years old ● Hibernate – 230 years of effort – 21 years old
  • 6. 6 ORM: Older products ● Drupal - 22 years old ● ASP.NET – 20 years old ● J2EE – c.f. Hibernate – Enterprise JavaBeans – 25 years old ● WebObjects – 1996-2008 – 12 years
  • 7. 7 Rust ORM: schema crate ● Create a separate crate with the schema – OpenAPI/JSONSchema definitions – Rust struct’s generated by progenitor, including serialisation/deserialisation functionality ● Due to Rust’s trait impl coherence rules, database persistence needs to be added to these structs ● Generate for other languages such as TypeScript
  • 8. 8 Rust ORM: Must have ● DQL & DML – Insert, for all data-types used in the schema – Update, … – Query, … ● Actively maintained ● Transaction support
  • 9. 9 Rust ORM: Nice to have ● Upsert – More efficient than alt.: query+insert+update ● PostgreSQL support ● Sqlite support – Very handy for light-weight tests ● DDL/Migration management – Another tool can be used for this
  • 10. 10 Rust ORMs: Popular (>1k*) ● Diesel - 18 years of effort – 8 years old ● Sea-ORM – 9 years of effort – 2 years old ● Rbatis – 7 years of effort – 3 years old Rust database framework ● sqlx - 2 years of effort – 10 years old
  • 11. 11 Rust ORMs: Obscure ● Ormx – 1 year of effort – 2.5 years old ● Rustorm – 2 years of effort – 5 years old - abandoned ● toql - 5 years of effort – 3 years old ● Summer-mybatis – 4 years of effort – 1 year old ● butane - 2 years of effort – 3.5 years old ● sprattus – 1 years of effort – 2 years old ● Yukino-dev - 2 years of effort – 2 years old ● Ormlite – 1 year of effort – 1 year old ● Tql - 2 years of effort - 7 years old NoSQL ORMs ● wither (mongo) - 1 year of effort – 5 years old
  • 12. 12 Rust ORM: diesel use diesel::prelude::*; #[derive(Queryable)] pub struct Post { pub id: i32, pub title: String, pub body: String, pub published: bool, } Add derives … looks simple
  • 13. 13 Rust ORM: diesel diesel::table! { posts (id) { id -> Int4, title -> Varchar, body -> Text, published -> Bool, } } Except diesel needs a “schema.rs” that defines the database fields for one database Maybe can be generated by diesel API, and injected using progenitor’s “post” hook.
  • 14. 14 Rust ORM: Sea-ORM #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Deserialize, Serialize)] #[sea_orm(table_name = "posts")] pub struct Model { #[sea_orm(primary_key)] #[serde(skip_deserializing)] pub id: i32, pub title: String, #[sea_orm(column_type = "Text")] pub text: String, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation {} impl ActiveModelBehavior for ActiveModel {} Every model must be called Model
  • 15. 15 Rust ORM: butane #[model] #[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize, ToSchema)] pub struct Blog { #[serde(default)] pub posts: Many<Post>, #[pk] pub blog_id: uuid::Uuid, #[serde(default, skip_serializing_if = "Option::is_none")] pub slug: Option<String>, } Requires primary keys, and relations Vec → Many
  • 17. 17 Migrations: Benefits ● Rollback Migrations: Negatives ● More effort than deleting and installing schema each deploy... i.e. there are no negatives Migrations
  • 18. 18 Migrations: Must have ● Schema version stored in each database instance Migrations
  • 19. 19 Migrations: Must have after v1 ● Migration batch support – After v1 of any project, new versions of a product will be released at intervals that include many schema changes that were part of different pull requests Migrations
  • 20. 20 Migrations: Nice to have ● Per-change undo – Mostly used by developers when: ● Switching branches ● Developing migrations – Developers can manually undo changes Migrations
  • 21. 21 Migrations: Nice to have ● Rollback – Alternative is use backup and restore Migrations
  • 22. 22 Migrations: Nice to have ● Zero-downtime migrations – Avoid locking – Schema changes have three phases 1) Additive changes 2) Update services 3) Either 1) Rollback if services stable, or 2) Destructive changes to the schema Migrations
  • 23. 23 Migrations: Nice to have ● ORM integration – Allows database vendor agnostic migrations – Allows auto-generating migrations from model changes Migrations
  • 24. 24 Rust Migration ● Reshape - 2 year of effort – 1 year old – Ticks most boxes, except no ORM integration, and PG only ● prisma-engines – 65 year of effort – 3 years old – TypeScript CLI ● Refinery – lacks undo features
  • 25. 25 TypeScript Migration ● prisma – 29 years of effort – 2 years old ● knex - 20 years of effort – 10 years old ● Typeorm - 50 years of effort – 6 years old
  • 26. 26 Go Migration ● Altas – 24 years of effort – 2 years old ● bytebase - 41 years of effort – 2 years old