Compare commits
	
		
			1 Commits
		
	
	
		
			89d1bbdd9e
			...
			remove_edi
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 7111431048 | 
| @ -7,11 +7,7 @@ def migrate_edition_to_editions_temp(apps, schema_editor): | |||||||
|     Purchase = apps.get_model("games", "Purchase") |     Purchase = apps.get_model("games", "Purchase") | ||||||
|     for purchase in Purchase.objects.all(): |     for purchase in Purchase.objects.all(): | ||||||
|         if purchase.edition: |         if purchase.edition: | ||||||
|             print( |  | ||||||
|                 f"Migrating Purchase {purchase.id} with Edition {purchase.edition.id}" |  | ||||||
|             ) |  | ||||||
|             purchase.editions_temp.add(purchase.edition) |             purchase.editions_temp.add(purchase.edition) | ||||||
|             print(purchase.editions_temp.all()) |  | ||||||
|             purchase.save() |             purchase.save() | ||||||
|         else: |         else: | ||||||
|             print(f"No edition found for Purchase {purchase.id}") |             print(f"No edition found for Purchase {purchase.id}") | ||||||
|  | |||||||
| @ -0,0 +1,28 @@ | |||||||
|  | # Generated by Django 5.1.3 on 2025-01-08 20:06 | ||||||
|  |  | ||||||
|  | import django.db.models.deletion | ||||||
|  | from django.db import migrations, models | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class Migration(migrations.Migration): | ||||||
|  |     dependencies = [ | ||||||
|  |         ("games", "0045_alter_purchase_editions"), | ||||||
|  |     ] | ||||||
|  |  | ||||||
|  |     operations = [ | ||||||
|  |         migrations.AddField( | ||||||
|  |             model_name="game", | ||||||
|  |             name="platform", | ||||||
|  |             field=models.ForeignKey( | ||||||
|  |                 blank=True, | ||||||
|  |                 default=None, | ||||||
|  |                 null=True, | ||||||
|  |                 on_delete=django.db.models.deletion.SET_DEFAULT, | ||||||
|  |                 to="games.platform", | ||||||
|  |             ), | ||||||
|  |         ), | ||||||
|  |         migrations.AlterUniqueTogether( | ||||||
|  |             name="game", | ||||||
|  |             unique_together={("name", "platform", "year_released")}, | ||||||
|  |         ), | ||||||
|  |     ] | ||||||
							
								
								
									
										61
									
								
								games/migrations/0047_auto_20250119_2129.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								games/migrations/0047_auto_20250119_2129.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,61 @@ | |||||||
|  | # Generated by Django 5.1.3 on 2025-01-19 20:29 | ||||||
|  |  | ||||||
|  | from django.db import connection, migrations, models | ||||||
|  |  | ||||||
|  |  | ||||||
|  | def recreate_games(apps, schema_editor): | ||||||
|  |     Edition = apps.get_model("games", "Edition") | ||||||
|  |     Game = apps.get_model("games", "Game") | ||||||
|  |     Purchase = apps.get_model("games", "Purchase") | ||||||
|  |  | ||||||
|  |     with connection.cursor() as cursor: | ||||||
|  |         print("Create table games_gametemp") | ||||||
|  |         cursor.execute( | ||||||
|  |             "CREATE TABLE games_gametemp AS SELECT * FROM games_game WHERE 1=0;" | ||||||
|  |         ) | ||||||
|  |  | ||||||
|  |         for edition in Edition.objects.all(): | ||||||
|  |             print(f"Re-create edition with ID {edition.id}") | ||||||
|  |             cursor.execute( | ||||||
|  |                 """ | ||||||
|  |                 INSERT INTO games_gametemp ( | ||||||
|  |                     id, name, sort_name, year_released, platform_id, wikidata, created_at | ||||||
|  |                 ) | ||||||
|  |                 VALUES (%s, %s, %s, %s, %s, %s, %s) | ||||||
|  |                 """, | ||||||
|  |                 [ | ||||||
|  |                     edition.id,  # Reuse the Edition ID | ||||||
|  |                     edition.name, | ||||||
|  |                     edition.sort_name, | ||||||
|  |                     edition.year_released, | ||||||
|  |                     edition.platform_id, | ||||||
|  |                     Game.objects.get(id=edition.game.id).wikidata, | ||||||
|  |                     edition.created_at, | ||||||
|  |                 ], | ||||||
|  |             ) | ||||||
|  |         print("Turn foreign keys off") | ||||||
|  |         cursor.execute("PRAGMA foreign_keys = OFF;") | ||||||
|  |         print("Drop table games_game") | ||||||
|  |         cursor.execute("DROP TABLE games_game;") | ||||||
|  |         print("Drop table games_edition") | ||||||
|  |         cursor.execute("DROP TABLE games_edition;") | ||||||
|  |         print("Rename table games_gametemp to games_game") | ||||||
|  |         # cursor.execute("ALTER TABLE games_gametemp RENAME TO games_game;") | ||||||
|  |         cursor.execute("CREATE TABLE games_game AS SELECT * FROM games_gametemp;") | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class Migration(migrations.Migration): | ||||||
|  |     dependencies = [ | ||||||
|  |         ("games", "0046_game_platform_alter_game_unique_together"), | ||||||
|  |     ] | ||||||
|  |  | ||||||
|  |     operations = [ | ||||||
|  |         migrations.RunPython(recreate_games), | ||||||
|  |         migrations.AlterField( | ||||||
|  |             model_name="purchase", | ||||||
|  |             name="editions", | ||||||
|  |             field=models.ManyToManyField( | ||||||
|  |                 blank=True, related_name="purchases", to="games.game" | ||||||
|  |             ), | ||||||
|  |         ), | ||||||
|  |     ] | ||||||
| @ -9,20 +9,6 @@ from django.utils import timezone | |||||||
| from common.time import format_duration | from common.time import format_duration | ||||||
|  |  | ||||||
|  |  | ||||||
| class Game(models.Model): |  | ||||||
|     name = models.CharField(max_length=255) |  | ||||||
|     sort_name = models.CharField(max_length=255, null=True, blank=True, default=None) |  | ||||||
|     year_released = models.IntegerField(null=True, blank=True, default=None) |  | ||||||
|     wikidata = models.CharField(max_length=50, null=True, blank=True, default=None) |  | ||||||
|     created_at = models.DateTimeField(auto_now_add=True) |  | ||||||
|  |  | ||||||
|     session_average: float | int | timedelta | None |  | ||||||
|     session_count: int | None |  | ||||||
|  |  | ||||||
|     def __str__(self): |  | ||||||
|         return self.name |  | ||||||
|  |  | ||||||
|  |  | ||||||
| class Platform(models.Model): | class Platform(models.Model): | ||||||
|     name = models.CharField(max_length=255) |     name = models.CharField(max_length=255) | ||||||
|     group = models.CharField(max_length=255, null=True, blank=True, default=None) |     group = models.CharField(max_length=255, null=True, blank=True, default=None) | ||||||
| @ -44,6 +30,26 @@ def get_sentinel_platform(): | |||||||
|     )[0] |     )[0] | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class Game(models.Model): | ||||||
|  |     class Meta: | ||||||
|  |         unique_together = [["name", "platform", "year_released"]] | ||||||
|  |  | ||||||
|  |     name = models.CharField(max_length=255) | ||||||
|  |     sort_name = models.CharField(max_length=255, null=True, blank=True, default=None) | ||||||
|  |     year_released = models.IntegerField(null=True, blank=True, default=None) | ||||||
|  |     platform = models.ForeignKey( | ||||||
|  |         Platform, on_delete=models.SET_DEFAULT, null=True, blank=True, default=None | ||||||
|  |     ) | ||||||
|  |     wikidata = models.CharField(max_length=50, null=True, blank=True, default=None) | ||||||
|  |     created_at = models.DateTimeField(auto_now_add=True) | ||||||
|  |  | ||||||
|  |     session_average: float | int | timedelta | None | ||||||
|  |     session_count: int | None | ||||||
|  |  | ||||||
|  |     def __str__(self): | ||||||
|  |         return self.name | ||||||
|  |  | ||||||
|  |  | ||||||
| class Edition(models.Model): | class Edition(models.Model): | ||||||
|     class Meta: |     class Meta: | ||||||
|         unique_together = [["name", "platform", "year_released"]] |         unique_together = [["name", "platform", "year_released"]] | ||||||
| @ -113,7 +119,7 @@ class Purchase(models.Model): | |||||||
|  |  | ||||||
|     objects = PurchaseQueryset().as_manager() |     objects = PurchaseQueryset().as_manager() | ||||||
|  |  | ||||||
|     editions = models.ManyToManyField(Edition, related_name="purchases", blank=True) |     editions = models.ManyToManyField(Game, related_name="purchases", blank=True) | ||||||
|     platform = models.ForeignKey( |     platform = models.ForeignKey( | ||||||
|         Platform, on_delete=models.CASCADE, default=None, null=True, blank=True |         Platform, on_delete=models.CASCADE, default=None, null=True, blank=True | ||||||
|     ) |     ) | ||||||
|  | |||||||
| @ -1443,10 +1443,6 @@ input:checked + .toggle-bg { | |||||||
|   margin-top: 1rem; |   margin-top: 1rem; | ||||||
| } | } | ||||||
|  |  | ||||||
| .ml-4 { |  | ||||||
|   margin-left: 1rem; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| .block { | .block { | ||||||
|   display: block; |   display: block; | ||||||
| } | } | ||||||
| @ -1475,10 +1471,6 @@ input:checked + .toggle-bg { | |||||||
|   display: grid; |   display: grid; | ||||||
| } | } | ||||||
|  |  | ||||||
| .list-item { |  | ||||||
|   display: list-item; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| .hidden { | .hidden { | ||||||
|   display: none; |   display: none; | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user