@@ -6,7 +6,8 @@ use std::iter;
66
77use crate :: enrollment:: Participation ;
88use crate :: enrollment:: {
9- EnrollmentChangeEvent , EnrollmentChangeEventType , EnrollmentsEvolver , ExperimentEnrollment ,
9+ DisqualifiedReason , EnrolledReason , EnrollmentChangeEvent , EnrollmentChangeEventType ,
10+ EnrollmentsEvolver , ExperimentEnrollment , NotEnrolledReason , PreviousGeckoPrefState ,
1011 map_enrollments,
1112} ;
1213use crate :: error:: { Result , debug, warn} ;
@@ -295,3 +296,107 @@ pub fn reset_telemetry_identifiers(
295296 }
296297 Ok ( events)
297298}
299+
300+ pub mod v3 {
301+ // This module contains legacy enrollment structs that mirror the schema of enrollments stored as they were in the database as of v3. These are used for deserializing pre-migration enrollments during the migration process, and should not be used outside of that context.
302+
303+ use super :: * ;
304+ use serde:: { Deserialize , Serialize } ;
305+
306+ #[ derive( Deserialize , Serialize , Debug , Clone , Hash , Eq , PartialEq ) ]
307+ pub enum LegacyNotEnrolledReason {
308+ DifferentAppName ,
309+ DifferentChannel ,
310+ EnrollmentsPaused ,
311+ FeatureConflict ,
312+ NotSelected ,
313+ NotTargeted ,
314+ OptOut ,
315+ }
316+
317+ #[ derive( Deserialize , Serialize , Debug , Clone , PartialEq , Eq ) ]
318+ pub struct LegacyExperimentEnrollment {
319+ pub slug : String ,
320+ pub status : LegacyEnrollmentStatus ,
321+ }
322+
323+ #[ derive( Deserialize , Serialize , Debug , Clone , Hash , Eq , PartialEq ) ]
324+ pub enum LegacyEnrollmentStatus {
325+ Enrolled {
326+ reason : EnrolledReason ,
327+ branch : String ,
328+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
329+ prev_gecko_pref_states : Option < Vec < PreviousGeckoPrefState > > ,
330+ } ,
331+ NotEnrolled {
332+ reason : LegacyNotEnrolledReason ,
333+ } ,
334+ Disqualified {
335+ reason : DisqualifiedReason ,
336+ branch : String ,
337+ } ,
338+ WasEnrolled {
339+ branch : String ,
340+ experiment_ended_at : u64 ,
341+ } ,
342+ Error {
343+ reason : String ,
344+ } ,
345+ }
346+
347+ impl From < LegacyNotEnrolledReason > for NotEnrolledReason {
348+ #[ allow( deprecated) ]
349+ fn from ( value : LegacyNotEnrolledReason ) -> Self {
350+ match value {
351+ LegacyNotEnrolledReason :: DifferentAppName => NotEnrolledReason :: DifferentAppName ,
352+ LegacyNotEnrolledReason :: DifferentChannel => NotEnrolledReason :: DifferentChannel ,
353+ LegacyNotEnrolledReason :: EnrollmentsPaused => NotEnrolledReason :: EnrollmentsPaused ,
354+ LegacyNotEnrolledReason :: FeatureConflict => NotEnrolledReason :: FeatureConflict {
355+ conflict_slug : None ,
356+ } ,
357+ LegacyNotEnrolledReason :: NotSelected => NotEnrolledReason :: NotSelected ,
358+ LegacyNotEnrolledReason :: NotTargeted => NotEnrolledReason :: NotTargeted ,
359+ LegacyNotEnrolledReason :: OptOut => NotEnrolledReason :: OptOut ,
360+ }
361+ }
362+ }
363+
364+ impl From < LegacyEnrollmentStatus > for EnrollmentStatus {
365+ fn from ( value : LegacyEnrollmentStatus ) -> Self {
366+ match value {
367+ LegacyEnrollmentStatus :: Enrolled {
368+ reason,
369+ branch,
370+ prev_gecko_pref_states,
371+ } => EnrollmentStatus :: Enrolled {
372+ reason,
373+ branch,
374+ prev_gecko_pref_states,
375+ } ,
376+ LegacyEnrollmentStatus :: NotEnrolled { reason } => EnrollmentStatus :: NotEnrolled {
377+ reason : reason. into ( ) ,
378+ } ,
379+ LegacyEnrollmentStatus :: Disqualified { reason, branch } => {
380+ EnrollmentStatus :: Disqualified { reason, branch }
381+ }
382+ LegacyEnrollmentStatus :: WasEnrolled {
383+ branch,
384+ experiment_ended_at,
385+ } => EnrollmentStatus :: WasEnrolled {
386+ branch,
387+ experiment_ended_at,
388+ } ,
389+ LegacyEnrollmentStatus :: Error { reason } => EnrollmentStatus :: Error { reason } ,
390+ }
391+ }
392+ }
393+
394+ impl From < LegacyExperimentEnrollment > for ExperimentEnrollment {
395+ fn from ( value : LegacyExperimentEnrollment ) -> Self {
396+ ExperimentEnrollment {
397+ slug : value. slug ,
398+ status : value. status . into ( ) ,
399+ }
400+ }
401+ }
402+ }
0 commit comments