-
-
Notifications
You must be signed in to change notification settings - Fork 606
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
POWERSYNC prototype: add migration to create postgresql publication #1747
Draft
Dieterbe
wants to merge
19
commits into
master
Choose a base branch
from
powersync
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
71fc1c6
add migration to create postgresql publication
Dieterbe 4c9cc2d
Update react files and set type="module"
rolandgeider 8c2eca0
Add URL to get token for powersync
rolandgeider 0ba5d2c
Merge branch 'refs/heads/master' into powersync
rolandgeider 5e2bd2b
Return powersync public key(s)
rolandgeider 5f71782
Don't use the login_required decorator
rolandgeider f5f67bf
Fix the powersync key generation
rolandgeider 4659aa4
Install python-jose via simplejwt
rolandgeider bd3d939
just create the publication for all tables.
Dieterbe 33971f0
Allow migration to run on non-postgres databases
rolandgeider 2b6949f
todo
Dieterbe c6163de
Add foreign key to the user table
rolandgeider aec1246
Revert "Add foreign key to the user table"
rolandgeider 8a6c2b4
Split migrations
rolandgeider a081a2b
Merge branch 'master' into powersync
rolandgeider 22a72f9
Add development Dockerfile with additional packages
rolandgeider f700637
Add UUIDs to some of the nutrition models
rolandgeider 4ef534e
give dummy meals names
Dieterbe 9514316
also translate foreign keys to uuid's
Dieterbe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# | ||
# Installs some additional packages needed for development | ||
# | ||
# Note that this dockerfile is built from the corresponding docker-compose file | ||
# | ||
|
||
FROM wger/server:latest | ||
|
||
USER root | ||
|
||
WORKDIR /home/wger/src | ||
RUN apt-get update && \ | ||
apt-get install -y \ | ||
git \ | ||
vim \ | ||
yarnpkg \ | ||
sassc | ||
|
||
COPY ../../../requirements.txt /tmp/requirements.txt | ||
COPY ../../../requirements_dev.txt /tmp/requirements_dev.txt | ||
|
||
RUN ln -s /usr/bin/yarnpkg /usr/bin/yarn \ | ||
&& ln -s /usr/bin/sassc /usr/bin/sass | ||
|
||
USER wger | ||
RUN pip3 install --break-system-packages --user -r /tmp/requirements.txt \ | ||
&& pip3 install --break-system-packages --user -r /tmp/requirements_dev.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
wger/core/migrations/0018_create_publication_add_ivm_extension.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Generated by Django 4.2.13 on 2024-09-19 13:43 | ||
|
||
from django.db import migrations | ||
|
||
from wger.utils.db import postgres_only | ||
|
||
|
||
@postgres_only | ||
def add_publication(apps, schema_editor): | ||
# Note that "FOR ALL TABLES" applies for all tables created in the future as well | ||
schema_editor.execute( | ||
""" | ||
DO $$ | ||
BEGIN | ||
IF NOT EXISTS ( | ||
SELECT 1 FROM pg_publication WHERE pubname = 'powersync' | ||
) THEN | ||
CREATE PUBLICATION powersync FOR ALL TABLES; | ||
END IF; | ||
END $$; | ||
""" | ||
) | ||
|
||
|
||
@postgres_only | ||
def remove_publication(apps, schema_editor): | ||
schema_editor.execute('DROP PUBLICATION IF EXISTS powersync;') | ||
|
||
|
||
@postgres_only | ||
def add_ivm_extension(apps, schema_editor): | ||
schema_editor.execute('CREATE EXTENSION IF NOT EXISTS pg_ivm;') | ||
|
||
|
||
@postgres_only | ||
def remove_ivm_extension(apps, schema_editor): | ||
schema_editor.execute('DROP EXTENSION IF EXISTS pg_ivm;') | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('core', '0017_language_full_name_en'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(add_publication, reverse_code=remove_publication), | ||
migrations.RunPython(add_ivm_extension, reverse_code=remove_ivm_extension), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# Generated by Django 4.2.16 on 2024-10-19 21:04 | ||
|
||
from django.db import migrations, models | ||
import uuid | ||
|
||
|
||
def gen_uuids(apps, schema_editor): | ||
NutritionPlan = apps.get_model('nutrition', 'NutritionPlan') | ||
Meal = apps.get_model('nutrition', 'Meal') | ||
MealItem = apps.get_model('nutrition', 'MealItem') | ||
LogItem = apps.get_model('nutrition', 'LogItem') | ||
|
||
for item in LogItem.objects.all(): | ||
item.uuid = uuid.uuid4() | ||
item.save(update_fields=['uuid']) | ||
|
||
for item in MealItem.objects.all(): | ||
item.uuid = uuid.uuid4() | ||
item.save(update_fields=['uuid']) | ||
|
||
for meal in Meal.objects.all(): | ||
meal.uuid = uuid.uuid4() | ||
meal.save(update_fields=['uuid']) | ||
|
||
for plan in NutritionPlan.objects.all(): | ||
plan.uuid = uuid.uuid4() | ||
plan.save(update_fields=['uuid']) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
('nutrition', '0024_remove_ingredient_status'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='nutritionplan', | ||
name='uuid', | ||
field=models.UUIDField( | ||
default=uuid.uuid4, | ||
editable=False, | ||
null=True, | ||
unique=False, | ||
), | ||
), | ||
migrations.AddField( | ||
model_name='meal', | ||
name='uuid', | ||
field=models.UUIDField( | ||
default=uuid.uuid4, | ||
editable=False, | ||
null=True, | ||
unique=False, | ||
), | ||
), | ||
migrations.AddField( | ||
model_name='mealitem', | ||
name='uuid', | ||
field=models.UUIDField( | ||
default=uuid.uuid4, | ||
editable=False, | ||
null=True, | ||
unique=False, | ||
), | ||
), | ||
migrations.AddField( | ||
model_name='logitem', | ||
name='uuid', | ||
field=models.UUIDField( | ||
default=uuid.uuid4, | ||
editable=False, | ||
null=True, | ||
unique=False, | ||
), | ||
), | ||
# Generate UUIDs | ||
migrations.RunPython( | ||
gen_uuids, | ||
reverse_code=migrations.RunPython.noop, | ||
), | ||
# Set uuid fields to non-nullable | ||
migrations.AlterField( | ||
model_name='nutritionplan', | ||
name='uuid', | ||
field=models.UUIDField( | ||
default=uuid.uuid4, | ||
editable=False, | ||
null=False, | ||
unique=True, | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name='meal', | ||
name='uuid', | ||
field=models.UUIDField( | ||
default=uuid.uuid4, | ||
editable=False, | ||
null=False, | ||
unique=True, | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name='mealitem', | ||
name='uuid', | ||
field=models.UUIDField( | ||
default=uuid.uuid4, | ||
editable=False, | ||
null=False, | ||
unique=True, | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name='logitem', | ||
name='uuid', | ||
field=models.UUIDField( | ||
default=uuid.uuid4, | ||
editable=False, | ||
null=False, | ||
unique=True, | ||
), | ||
), | ||
] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Copilot Autofix AI 3 months ago
To fix the problem, we need to ensure that detailed exception messages are not exposed to the end user. Instead, we should log the detailed error message on the server and return a generic error message to the client. This can be achieved by modifying the exception handling in the
get_powersync_token
function.logging
module if not already imported.