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

Usertransfer from production(beta) to release version of the app #359

Merged
merged 15 commits into from
Dec 1, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add migration test in internal settings
PaulPickhardt committed Nov 30, 2023
commit d89cb57b37cde6cf319708d68905e89946b02e3a
100 changes: 90 additions & 10 deletions lib/migration/services.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import 'dart:convert';

import 'package:flutter/material.dart' hide Shortcuts;
import 'package:priobike/home/models/shortcut.dart';
import 'package:priobike/home/models/shortcut_location.dart';
import 'package:priobike/home/models/shortcut_route.dart';
import 'package:priobike/home/services/shortcuts.dart';
import 'package:priobike/main.dart';
import 'package:priobike/routing/models/waypoint.dart';
import 'package:priobike/settings/models/backend.dart';
import 'package:shared_preferences/shared_preferences.dart';

@@ -90,43 +94,119 @@ class Migration {

/// Migrate the search history (production/release => Hamburg).
Future<void> migrateSearchHistoryProduction() async {
final preferences = await SharedPreferences.getInstance();
final storage = await SharedPreferences.getInstance();

// Load production and release lists.
List<String>? searchHistoryListProduction =
preferences.getStringList("priobike.routing.searchHistory.${Backend.production.name}");
storage.getStringList("priobike.routing.searchHistory.${Backend.production.name}");
// Return on no key found.
if (searchHistoryListProduction == null) return;

List<String> searchHistoryListRelease =
preferences.getStringList("priobike.routing.searchHistory.${Backend.release.name}") ?? [];
storage.getStringList("priobike.routing.searchHistory.${Backend.release.name}") ?? [];
// Concat both lists.
searchHistoryListRelease.addAll(searchHistoryListProduction);
// Store concatenated list.
await preferences.setStringList(
await storage.setStringList(
"priobike.routing.searchHistory.${Backend.release.regionName}", searchHistoryListRelease);
// Remove old list.
await preferences.remove("priobike.routing.searchHistory.${Backend.production.name}");
await storage.remove("priobike.routing.searchHistory.${Backend.production.name}");
}

/// Migrate the search history (staging => Dresden).
Future<void> migrateSearchHistoryStaging() async {
final preferences = await SharedPreferences.getInstance();
final storage = await SharedPreferences.getInstance();

// Load production and release lists.
List<String>? searchHistoryListStaging =
preferences.getStringList("priobike.routing.searchHistory.${Backend.staging.name}");
storage.getStringList("priobike.routing.searchHistory.${Backend.staging.name}");
// Return on no key found.
if (searchHistoryListStaging == null) return;

List<String> searchHistoryListStagingNew =
preferences.getStringList("priobike.routing.searchHistory.${Backend.staging.regionName}") ?? [];
storage.getStringList("priobike.routing.searchHistory.${Backend.staging.regionName}") ?? [];
// Concat both lists.
searchHistoryListStagingNew.addAll(searchHistoryListStaging);
// Store concatenated list.
await preferences.setStringList(
await storage.setStringList(
"priobike.routing.searchHistory.${Backend.staging.regionName}", searchHistoryListStagingNew);
// Remove old list.
await preferences.remove("priobike.routing.searchHistory.${Backend.staging.name}");
await storage.remove("priobike.routing.searchHistory.${Backend.staging.name}");
}

/// Adds test migration data for all backends.
Future<void> addTestMigrationData() async {
final storage = await SharedPreferences.getInstance();

// Create old data for Staging.
List<Shortcut> stagingList = [
ShortcutLocation(
id: UniqueKey().toString(),
name: "Staging-Location-Test",
waypoint: Waypoint(51.038294, 13.703280, address: "Clara-Viebig-Straße 9"),
),
ShortcutRoute(
id: UniqueKey().toString(),
name: "Staging-Route-Test",
waypoints: [
Waypoint(51.038294, 13.703280, address: "Clara-Viebig-Straße 9"),
Waypoint(50.979067, 13.882596, address: "Elberadweg Heidenau"),
],
),
];

final jsonStrStaging = jsonEncode(stagingList.map((e) => e.toJson()).toList());

storage.setString("priobike.home.shortcuts.${Backend.staging.name}", jsonStrStaging);

// Create old data for Production.
List<Shortcut> productionList = [
ShortcutLocation(
id: UniqueKey().toString(),
name: "Production-Location-Test",
waypoint: Waypoint(53.5415701077766, 9.984275605794686, address: "Staging-test"),
),
ShortcutRoute(
id: UniqueKey().toString(),
name: "Production-Route-Test",
waypoints: [
Waypoint(53.560863, 9.990909, address: "Theodor-Heuss-Platz, Hamburg"),
Waypoint(53.564378, 9.978001, address: "Rentzelstraße 55, 20146 Hamburg"),
],
),
];

final jsonStrProduction = jsonEncode(productionList.map((e) => e.toJson()).toList());

storage.setString("priobike.home.shortcuts.${Backend.production.name}", jsonStrProduction);

// Create old data for Release.
List<Shortcut> releaseList = [
ShortcutLocation(
id: UniqueKey().toString(),
name: "Release-Location-Test",
waypoint: Waypoint(53.5415701077766, 9.984275605794686, address: "Staging-test"),
),
ShortcutRoute(
id: UniqueKey().toString(),
name: "Release-Route-Test",
waypoints: [
Waypoint(53.560863, 9.990909, address: "Theodor-Heuss-Platz, Hamburg"),
Waypoint(53.564378, 9.978001, address: "Rentzelstraße 55, 20146 Hamburg"),
],
),
];

final jsonStrRelease = jsonEncode(releaseList.map((e) => e.toJson()).toList());

storage.setString("priobike.home.shortcuts.${Backend.release.name}", jsonStrRelease);

// Create old search history data.
await storage.setStringList("priobike.routing.searchHistory.${Backend.staging.name}",
[json.encode(Waypoint(51.038294, 13.703280, address: "Clara-Viebig-Straße 9").toJSON())]);
await storage.setStringList("priobike.routing.searchHistory.${Backend.production.name}",
[json.encode(Waypoint(53.560863, 9.990909, address: "Theodor-Heuss-Platz, Hamburg").toJSON())]);
await storage.setStringList("priobike.routing.searchHistory.${Backend.release.name}",
[json.encode(Waypoint(53.560863, 9.990909, address: "Theodor-Heuss-Platz, Hamburg").toJSON())]);
}
}
2 changes: 1 addition & 1 deletion lib/migration/user_transfer_view.dart
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ class UserTransferViewState extends State<UserTransferView> {
@override
Widget build(BuildContext context) {
// Display when backend ist not release and user did not seen this view yet.
if ((settings.didViewUserTransfer == true || settings.backend == Backend.release) &&
if ((settings.didViewUserTransfer == true || settings.backend != Backend.production) &&
(!isUserTransferring) &&
(widget.child != null)) {
return widget.child!;
23 changes: 23 additions & 0 deletions lib/settings/views/internal.dart
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ import 'package:priobike/gamification/common/services/user_service.dart';
import 'package:priobike/gamification/goals/services/goals_service.dart';
import 'package:priobike/home/services/shortcuts.dart';
import 'package:priobike/main.dart';
import 'package:priobike/migration/services.dart';
import 'package:priobike/news/services/news.dart';
import 'package:priobike/positioning/services/positioning.dart';
import 'package:priobike/privacy/services.dart';
@@ -162,6 +163,11 @@ class InternalSettingsViewState extends State<InternalSettingsView> {
if (mounted) Navigator.pop(context);
}

/// A callback that adds test migration data for testing.
void addTestMigrationData() {
Migration().addTestMigrationData();
}

@override
Widget build(BuildContext context) {
return AnnotatedRegionWrapper(
@@ -361,6 +367,23 @@ class InternalSettingsViewState extends State<InternalSettingsView> {
),
),
const SmallVSpace(),
Padding(
padding: const EdgeInsets.only(left: 34, top: 8, bottom: 8, right: 24),
child: Small(
text:
"Durch Migration testen werden jeweils ein alter Shortcut und eine alte Suchanfrage angelegt (staging, production, release). Diese müssten nach einem Neustart der App jeweils mit angezeigt werden.",
context: context,
),
),
Padding(
padding: const EdgeInsets.only(top: 8),
child: SettingsElement(
title: "Migration testen",
icon: Icons.start,
callback: addTestMigrationData,
),
),
const SmallVSpace(),
],
),
),