Skip to content

Commit

Permalink
Merge pull request #57 from enesonus/OVTF-157-dev
Browse files Browse the repository at this point in the history
OVTF-157-dev: DB Migrations-improvements
  • Loading branch information
enesonus authored Nov 18, 2023
2 parents 129f22d + 2143e4e commit 9e184d5
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 5 deletions.
4 changes: 2 additions & 2 deletions DB_PLAN.MD
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@

Relationships:

- A User can have multiple UserSongRatings (One-to-Many)
- A Song can have multiple UserSongRatings (One-to-Many)
- A User can have multiple UserSongRating (One-to-Many)
- A Song can have multiple UserSongRating (One-to-Many)
- A Song can belong to multiple Albums (Many-to-Many), represented by AlbumSong
- A Song can be by multiple Artists (Many-to-Many), represented by SongArtist
- A Genre can include many Songs (One-to-Many)
Expand Down
3 changes: 3 additions & 0 deletions OVTF_Backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,6 @@ def delete(self):
self.is_active = False
self.deleted_at = timezone.now()
self.save()

def hard_delete(self):
super().delete()
18 changes: 18 additions & 0 deletions apps/songs/migrations/0007_alter_song_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.7 on 2023-11-18 23:22

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('songs', '0006_song_albums_song_artists_song_genres_and_more'),
]

operations = [
migrations.AlterField(
model_name='song',
name='version',
field=models.CharField(blank=True, max_length=50, null=True),
),
]
6 changes: 4 additions & 2 deletions apps/songs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class Song(CoreModel):
genres = models.ManyToManyField('Genre', through='GenreSong')
artists = models.ManyToManyField('Artist', through='ArtistSong')
albums = models.ManyToManyField('Album', through='AlbumSong')
instruments = models.ManyToManyField('Instrument', through='InstrumentSong')
instruments = models.ManyToManyField('Instrument',
through='InstrumentSong')
release_year = models.PositiveIntegerField()
duration = models.DurationField()
tempo = models.CharField(max_length=1, choices=Tempo.choices)
Expand All @@ -52,7 +53,8 @@ class Song(CoreModel):
max_length=1,
choices=RecordedEnvironment.choices)
replay_count = models.PositiveIntegerField(default=0)
version = models.CharField(max_length=50, blank=True)
version = models.CharField(max_length=50,
blank=True, null=True,)
img_url = models.URLField(max_length=300, blank=True, null=True)

def __str__(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 4.2.7 on 2023-11-18 22:58

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('songs', '0006_song_albums_song_artists_song_genres_and_more'),
('users', '0004_alter_user_img_url'),
]

operations = [
migrations.AddField(
model_name='user',
name='friends',
field=models.ManyToManyField(through='users.Friend', to='users.user'),
),
migrations.AddField(
model_name='user',
name='ratings',
field=models.ManyToManyField(through='users.UserSongRating', to='songs.song'),
),
migrations.RemoveField(
model_name='usersongrating',
name='date_rated',
),
migrations.AddField(
model_name='user',
name='user_preferences',
field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='preferences', to='users.userpreferences'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 4.2.7 on 2023-11-18 23:00

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('users', '0005_remove_usersongrating_date_rated_user_friends_and_more'),
]

operations = [
]
17 changes: 17 additions & 0 deletions apps/users/migrations/0007_remove_user_ratings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.7 on 2023-11-18 23:22

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('users', '0006_remove_usersongrating_date_rated_and_more'),
]

operations = [
migrations.RemoveField(
model_name='user',
name='ratings',
),
]
8 changes: 7 additions & 1 deletion apps/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class User(CoreModel):
img_url = models.URLField(max_length=300, blank=True, null=True)
date_joined = models.DateTimeField(default=timezone.now)
last_login = models.DateTimeField()
user_preferences = models.OneToOneField("UserPreferences",
related_name='preferences',
on_delete=models.CASCADE,
null=True,)
friends = models.ManyToManyField("self", through="Friend",
symmetrical=True,
through_fields=("user", "friend"))

def __str__(self):
return str(self.username)
Expand All @@ -24,7 +31,6 @@ class UserSongRating(CoreModel):
user = models.ForeignKey(User, on_delete=models.CASCADE)
song = models.ForeignKey(Song, on_delete=models.CASCADE)
rating = models.DecimalField(max_digits=4, decimal_places=2)
date_rated = models.DateTimeField(default=timezone.now)

def __str__(self):
return f"{self.user.__str__()} - {self.song.__str__()}"
Expand Down

0 comments on commit 9e184d5

Please sign in to comment.