-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
add support for default_version
in control file
#153
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
61130e8
add default version to the app.packages table
imor 7398c4a
update public.packages view to include default_version column
imor 9f6819d
add default_version arg in publish_package function
imor 7406589
add missing permissions on the default_version_struct column
imor 40b55c1
send default_version in 'dbdev publish' command
imor fc18602
update dbdev in db client to support default_version
imor a29461d
allow setting base_url and api_key in dbdev.install to help test locally
imor 005a3a1
add a comment
imor 8fecb4d
add a couple of more comments
imor cf226c8
correct version ordering
imor 5f6b732
drop ambiguous function
imor 5da5c82
only calling pgtle.set_default_version if default_version is non-null
imor 392801e
correct order of dropping and uninstalling the supabase-dbdev extension
imor 9aee3e7
Merge branch 'master' into add_default_version
imor 9ca2b78
fix dbdev version in download notice call
imor 46d0c7e
use control_description instead of name for TLE's description
imor 1ef85d5
make app.default_version_struct column non-null
imor 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
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
95 changes: 95 additions & 0 deletions
95
supabase/migrations/20231205051816_add_default_version.sql
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,95 @@ | ||
-- default_version column has a default value '0.0.0' only temporarily because the column is not null. | ||
-- It will be removed below. | ||
alter table app.packages | ||
add column default_version_struct app.semver not null default app.text_to_semver('0.0.0'), | ||
add column default_version text generated always as (app.semver_to_text(default_version_struct)) stored; | ||
|
||
-- for now we set the default version to current latest version | ||
-- new client will allow users to set a specific default version in the control file | ||
update app.packages | ||
set default_version_struct = app.text_to_semver(pp.latest_version) | ||
from public.packages pp | ||
where packages.id = pp.id; | ||
|
||
-- now that every row has a valid default_version, remove the default value of '0.0.0' | ||
alter table app.packages | ||
alter column default_version_struct drop default; | ||
|
||
-- add new default_version column to the view | ||
create or replace view public.packages as | ||
select | ||
pa.id, | ||
pa.package_name, | ||
pa.handle, | ||
pa.partial_name, | ||
newest_ver.version as latest_version, | ||
newest_ver.description_md, | ||
pa.control_description, | ||
pa.control_requires, | ||
pa.created_at, | ||
pa.default_version | ||
from | ||
app.packages pa, | ||
lateral ( | ||
select * | ||
from app.package_versions pv | ||
where pv.package_id = pa.id | ||
order by pv.version_struct desc | ||
limit 1 | ||
) newest_ver; | ||
|
||
-- grant insert and update permissions to authenticated users on the new default_version_struct column | ||
grant insert (partial_name, handle, control_description, control_relocatable, control_requires, default_version_struct) | ||
on app.packages | ||
to authenticated; | ||
|
||
grant update (control_description, control_relocatable, control_requires, default_version_struct) | ||
on app.packages | ||
to authenticated; | ||
|
||
-- publish_package accepts an additional `default_version` argument | ||
drop function public.publish_package(app.valid_name, varchar, bool, text[]); | ||
create or replace function public.publish_package( | ||
package_name app.valid_name, | ||
package_description varchar(1000), | ||
relocatable bool default false, | ||
requires text[] default '{}', | ||
default_version text default null | ||
) | ||
returns void | ||
language plpgsql | ||
as $$ | ||
declare | ||
account app.accounts = account from app.accounts account where id = auth.uid(); | ||
require text; | ||
begin | ||
if account.handle is null then | ||
raise exception 'user not logged in'; | ||
end if; | ||
|
||
if default_version is null then | ||
raise exception 'default_version is required. If you are on `dbdev` CLI version 0.1.5 or older upgrade to the latest version.'; | ||
end if; | ||
Comment on lines
+70
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the client doesn't send |
||
|
||
foreach require in array requires | ||
loop | ||
if not exists ( | ||
select true | ||
from app.allowed_extensions | ||
where | ||
name = require | ||
) then | ||
raise exception '`requires` in the control file can''t have `%` in it', require; | ||
end if; | ||
end loop; | ||
|
||
insert into app.packages(handle, partial_name, control_description, control_relocatable, control_requires, default_version_struct) | ||
values (account.handle, package_name, package_description, relocatable, requires, app.text_to_semver(default_version)) | ||
on conflict on constraint packages_handle_partial_name_key | ||
do update | ||
set control_description = excluded.control_description, | ||
control_relocatable = excluded.control_relocatable, | ||
control_requires = excluded.control_requires, | ||
default_version_struct = excluded.default_version_struct; | ||
end; | ||
$$; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default_version_struct
is not longer nullable.