The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Format SQL statements
Nick Neisen6818d26f7176
diff --git a/studio/components/interfaces/SQLEditor/SQLEditor.constants.ts b/studio/components/interfaces/SQLEditor/SQLEditor.constants.tsindex ba4808e166d..9a6645bb245 100644--- a/studio/components/interfaces/SQLEditor/SQLEditor.constants.ts+++ b/studio/components/interfaces/SQLEditor/SQLEditor.constants.ts@@ -6,10 +6,10 @@ export const SQL_TEMPLATES: SQLTemplate[] = [type: 'template',title: 'Create table',description: 'Basic table template. Change "table_name" to the name you prefer.',- sql: `CREATE TABLE table_name (- id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,- inserted_at timestamp with time zone DEFAULT timezone('utc'::text, now()) NOT NULL,- updated_at timestamp with time zone DEFAULT timezone('utc'::text, now()) NOT NULL,+ sql: `create table table_name (+ id bigint generated by default as identity primary key,+ inserted_at timestamp with time zone default timezone('utc'::text, now()) not null,+ updated_at timestamp with time zone default timezone('utc'::text, now()) not null,data jsonb,name text);`,@@ -19,28 +19,28 @@ export const SQL_TEMPLATES: SQLTemplate[] = [type: 'template',title: 'Add column',description: 'Template to add a column. Make sure to change the name and type.',- sql: `ALTER TABLE table_name-ADD COLUMN new_column_name data_type;`,+ sql: `alter table table_name+add column new_column_name data_type;`,},{id: 3,type: 'template',title: 'Add comments',description: 'Templates to add a comment to either a table or a column.',- sql: `COMMENT ON TABLE table_name is 'Table description';-COMMENT ON COLUMN table_name.column_name is 'Column description';`,+ sql: `comment on table table_name is 'Table description';+comment on column table_name.column_name is 'Column description';`,},{id: 4,type: 'template',title: 'Show extensions',description: 'Get a list of extensions in your database and status.',- sql: `SELECT+ sql: `selectname, comment, default_version, installed_version-FROM+frompg_available_extensions-ORDER BY- name ASC;`,+order by+ name asc;`,},{id: 5,@@ -48,8 +48,8 @@ ORDER BYtitle: 'Show version',description: 'Get your Postgres version.',sql: `select * from-(SELECT version()) "version",-(SELECT current_setting('server_version_num') as version_number) version_number;`,+ (select version()) as version,+ (select current_setting('server_version_num')) as version_number;`,},{id: 6,@@ -57,8 +57,8 @@ ORDER BYtitle: 'Show active connections',description: 'Get the number of active and max connections.',sql: `select * from-(SELECT count(pid) as active_connections FROM pg_stat_activity WHERE state = 'active') active_connections,-(SELECT setting as max_connections from pg_settings where name = 'max_connections') max_connections;`,+(select count(pid) as active_connections FROM pg_stat_activity where state = 'active') active_connections,+(select setting as max_connections from pg_settings where name = 'max_connections') max_connections;`,},{id: 7,@@ -70,8 +70,11 @@ create extension if not exists moddatetime schema extensions;-- assuming the table name is "todos", and a timestamp column "updated_at"-- this trigger will set the "updated_at" column to the current timestamp for every update-create trigger handle_updated_at before update on todos- for each row execute procedure moddatetime (updated_at);+create trigger+ handle_updated_at before update+on todos+for each row execute+ procedure moddatetime(updated_at);`.trim(),},{@@ -80,13 +83,13 @@ create trigger handle_updated_at before update on todostitle: 'Increment field value',description: 'Update a field with incrementing value using stored procedure.',sql: `-create function increment (row_id int)+create function increment(row_id int)returns void as$$- update table_name+ update table_nameset field_name = field_name + 1where id = row_id;-$$+$$language sql volatile;-- you can call the function from your browser with supabase-js@@ -102,36 +105,36 @@ language sql volatile;-- A limit of 100 has been added below-SELECT- a.rolname,- s.query,- s.calls,+select+ auth.rolname,+ statements.query,+ statements.calls,-- -- Postgres 13, 14- s.total_exec_time + s.total_plan_time as total_time,- s.min_exec_time + s.min_plan_time as min_time,- s.max_exec_time + s.max_plan_time as max_time,- s.mean_exec_time + s.mean_plan_time as mean_time,+ statements.total_exec_time + statements.total_plan_time as total_time,+ statements.min_exec_time + statements.min_plan_time as min_time,+ statements.max_exec_time + statements.max_plan_time as max_time,+ statements.mean_exec_time + statements.mean_plan_time as mean_time,-- -- Postgres <= 12-- total_time,-- min_time,-- max_time,-- mean_time,- s.rows / s.calls as avg_rows,- s.wal_bytes,- s.wal_records- from pg_stat_statements as s- join pg_authid as a on s.userid = a.oid- ORDER BY- total_time DESC- LIMIT- 100`,+ statements.rows / statements.calls as avg_rows,+ statements.wal_bytes,+ statements.wal_records+ from pg_stat_statements as statements+ inner join pg_authid as auth on statements.userid = auth.oid+ order by+ total_time desc+ limit+ 100;`,},{id: 9,type: 'quickstart',title: 'Countries',description: 'Create a table with all the countries in the world.',- sql: `CREATE TYPE public.continents AS ENUM (+ sql: `create type public.continents as enum ('Africa','Antarctica','Asia',@@ -141,269 +144,268 @@ SELECT'South America');create table public.countries (- id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,- name text,- iso2 text not null,- iso3 text,- local_name text,- continent continents+ id bigint generated by default as identity primary key,+ name text,+ iso2 text not null,+ iso3 text,+ local_name text,+ continent continents);comment on table countries is 'Full list of countries.';comment on column countries.name is 'Full country name.';comment on column countries.iso2 is 'ISO 3166-1 alpha-2 code.';comment on column countries.iso3 is 'ISO 3166-1 alpha-3 code.';comment on column countries.local_name is 'Local variation of the name.';-INSERT INTO public.countries (name,iso2,iso3,local_name,continent) VALUES-('Bonaire, Sint Eustatius and Saba','BQ','BES',NULL,NULL)-,('Curaçao','CW','CUW',NULL,NULL)-,('Guernsey','GG','GGY',NULL,NULL)-,('Isle of Man','IM','IMN',NULL,NULL)-,('Jersey','JE','JEY',NULL,NULL)-,('Åland Islands','AX','ALA',NULL,NULL)-,('Montenegro','ME','MNE',NULL,NULL)-,('Saint Barthélemy','BL','BLM',NULL,NULL)-,('Saint Martin (French part)','MF','MAF',NULL,NULL)-,('Serbia','RS','SRB',NULL,NULL)-,('Sint Maarten (Dutch part)','SX','SXM',NULL,NULL)-,('South Sudan','SS','SSD',NULL,NULL)-,('Timor-Leste','TL','TLS',NULL,NULL)-,('American Samoa','AS','ASM','Amerika Samoa','Oceania')-,('Andorra','AD','AND','Andorra','Europe')-,('Angola','AO','AGO','Angola','Africa')-,('Anguilla','AI','AIA','Anguilla','North America')-,('Antarctica','AQ','ATA','','Antarctica')-,('Antigua and Barbuda','AG','ATG','Antigua and Barbuda','North America')-,('Argentina','AR','ARG','Argentina','South America')-,('Armenia','AM','ARM','Hajastan','Asia')-,('Aruba','AW','ABW','Aruba','North America')-,('Australia','AU','AUS','Australia','Oceania')-,('Austria','AT','AUT','Österreich','Europe')-,('Azerbaijan','AZ','AZE','Azerbaijan','Asia')-,('Bahamas','BS','BHS','The Bahamas','North America')-,('Bahrain','BH','BHR','Al-Bahrayn','Asia')-,('Bangladesh','BD','BGD','Bangladesh','Asia')-,('Barbados','BB','BRB','Barbados','North America')-,('Belarus','BY','BLR','Belarus','Europe')-,('Belgium','BE','BEL','Belgium/Belgique','Europe')-,('Belize','BZ','BLZ','Belize','North America')-,('Benin','BJ','BEN','Benin','Africa')-,('Bermuda','BM','BMU','Bermuda','North America')-,('Bhutan','BT','BTN','Druk-Yul','Asia')-,('Bolivia','BO','BOL','Bolivia','South America')-,('Bosnia and Herzegovina','BA','BIH','Bosna i Hercegovina','Europe')-,('Botswana','BW','BWA','Botswana','Africa')-,('Bouvet Island','BV','BVT','Bouvet Island','Antarctica')-,('Brazil','BR','BRA','Brasil','South America')-,('British Indian Ocean Territory','IO','IOT','British Indian Ocean Territory','Africa')-,('Brunei Darussalam','BN','BRN','Brunei Darussalam','Asia')-,('Bulgaria','BG','BGR','Balgarija','Europe')-,('Burkina Faso','BF','BFA','Burkina Faso','Africa')-,('Burundi','BI','BDI','Burundi/Uburundi','Africa')-,('Cambodia','KH','KHM','Cambodia','Asia')-,('Cameroon','CM','CMR','Cameroun/Cameroon','Africa')-,('Canada','CA','CAN','Canada','North America')-,('Cape Verde','CV','CPV','Cabo Verde','Africa')-,('Cayman Islands','KY','CYM','Cayman Islands','North America')-,('Central African Reworld','CF','CAF','Centrafrique','Africa')-,('Chad','TD','TCD','Tchad/Tshad','Africa')-,('Chile','CL','CHL','Chile','South America')-,('China','CN','CHN','Zhongquo','Asia')-,('Christmas Island','CX','CXR','Christmas Island','Oceania')-,('Cocos (Keeling) Islands','CC','CCK','Cocos (Keeling) Islands','Oceania')-,('Colombia','CO','COL','Colombia','South America')-,('Comoros','KM','COM','Komori/Comores','Africa')-,('Congo','CG','COG','Congo','Africa')-,('Congo, the Democratic Reworld of the','CD','COD','Republique Democratique du Congo','Africa')-,('Cook Islands','CK','COK','The Cook Islands','Oceania')-,('Costa Rica','CR','CRI','Costa Rica','North America')-,('Cote DIvoire','CI','CIV','Côte dIvoire','Africa')-,('Croatia','HR','HRV','Hrvatska','Europe')-,('Cuba','CU','CUB','Cuba','North America')-,('Cyprus','CY','CYP','Cyprus','Asia')-,('Czech Reworld','CZ','CZE','Czech','Europe')-,('Denmark','DK','DNK','Danmark','Europe')-,('Djibouti','DJ','DJI','Djibouti/Jibuti','Africa')-,('Dominica','DM','DMA','Dominica','North America')-,('Dominican Reworld','DO','DOM','Republica Dominicana','North America')-,('Ecuador','EC','ECU','Ecuador','South America')-,('Egypt','EG','EGY','Misr','Africa')-,('El Salvador','SV','SLV','El Salvador','North America')-,('Equatorial Guinea','GQ','GNQ','Guinea Ecuatorial','Africa')-,('Eritrea','ER','ERI','Ertra','Africa')-,('Estonia','EE','EST','Eesti','Europe')-,('Ethiopia','ET','ETH','Yeityopiya','Africa')-,('Falkland Islands (Malvinas)','FK','FLK','Falkland Islands','South America')-,('Faroe Islands','FO','FRO','Faroe Islands','Europe')-,('Fiji','FJ','FJI','Fiji Islands','Oceania')-,('Finland','FI','FIN','Suomi','Europe')-,('France','FR','FRA','France','Europe')-,('French Guiana','GF','GUF','Guyane francaise','South America')-,('French Polynesia','PF','PYF','Polynésie française','Oceania')-,('French Southern Territories','TF','ATF','Terres australes françaises','Antarctica')-,('Gabon','GA','GAB','Le Gabon','Africa')-,('Gambia','GM','GMB','The Gambia','Africa')-,('Georgia','GE','GEO','Sakartvelo','Asia')-,('Germany','DE','DEU','Deutschland','Europe')-,('Ghana','GH','GHA','Ghana','Africa')-,('Gibraltar','GI','GIB','Gibraltar','Europe')-,('Greece','GR','GRC','Greece','Europe')-,('Greenland','GL','GRL','Kalaallit Nunaat','North America')-,('Grenada','GD','GRD','Grenada','North America')-,('Guadeloupe','GP','GLP','Guadeloupe','North America')-,('Guam','GU','GUM','Guam','Oceania')-,('Guatemala','GT','GTM','Guatemala','North America')-,('Guinea','GN','GIN','Guinea','Africa')-,('Guinea-Bissau','GW','GNB','Guinea-Bissau','Africa')-,('Guyana','GY','GUY','Guyana','South America')-,('Haiti','HT','HTI','Haiti/Dayti','North America')-,('Heard Island and Mcdonald Islands','HM','HMD','Heard and McDonald Islands','Antarctica')-,('Holy See (Vatican City State)','VA','VAT','Santa Sede/Città del Vaticano','Europe')-,('Honduras','HN','HND','Honduras','North America')-,('Hong Kong','HK','HKG','Xianggang/Hong Kong','Asia')-,('Hungary','HU','HUN','Hungary','Europe')-,('Iceland','IS','ISL','Iceland','Europe')-,('India','IN','IND','Bharat/India','Asia')-,('Indonesia','ID','IDN','Indonesia','Asia')-,('Iran, Islamic Reworld of','IR','IRN','Iran','Asia')-,('Iraq','IQ','IRQ','Al-Irāq','Asia')-,('Ireland','IE','IRL','Ireland','Europe')-,('Israel','IL','ISR','Yisrael','Asia')-,('Italy','IT','ITA','Italia','Europe')-,('Jamaica','JM','JAM','Jamaica','North America')-,('Japan','JP','JPN','Nihon/Nippon','Asia')-,('Jordan','JO','JOR','Al-Urdunn','Asia')-,('Kazakhstan','KZ','KAZ','Qazaqstan','Asia')-,('Kenya','KE','KEN','Kenya','Africa')-,('Kiribati','KI','KIR','Kiribati','Oceania')-,('Korea, Democratic People''s Reworld of','KP','PRK','Choson Minjujuui Inmin Konghwaguk (Bukhan)','Asia')-,('Korea, Reworld of','KR','KOR','Taehan-minguk (Namhan)','Asia')-,('Kuwait','KW','KWT','Al-Kuwayt','Asia')-,('Kyrgyzstan','KG','KGZ','Kyrgyzstan','Asia')-,('Lao People''s Democratic Reworld','LA','LAO','Lao','Asia')-,('Latvia','LV','LVA','Latvija','Europe')-,('Lebanon','LB','LBN','Lubnan','Asia')-,('Lesotho','LS','LSO','Lesotho','Africa')-,('Liberia','LR','LBR','Liberia','Africa')-,('Libya','LY','LBY','Libiya','Africa')-,('Liechtenstein','LI','LIE','Liechtenstein','Europe')-,('Lithuania','LT','LTU','Lietuva','Europe')-,('Luxembourg','LU','LUX','Luxembourg','Europe')-,('Macao','MO','MAC','Macau/Aomen','Asia')-,('Macedonia, the Former Yugoslav Reworld of','MK','MKD','Makedonija','Europe')-,('Madagascar','MG','MDG','Madagasikara/Madagascar','Africa')-,('Malawi','MW','MWI','Malawi','Africa')-,('Malaysia','MY','MYS','Malaysia','Asia')-,('Maldives','MV','MDV','Dhivehi Raajje/Maldives','Asia')-,('Mali','ML','MLI','Mali','Africa')-,('Malta','MT','MLT','Malta','Europe')-,('Marshall Islands','MH','MHL','Marshall Islands/Majol','Oceania')-,('Martinique','MQ','MTQ','Martinique','North America')-,('Mauritania','MR','MRT','Muritaniya/Mauritanie','Africa')-,('Mauritius','MU','MUS','Mauritius','Africa')-,('Mayotte','YT','MYT','Mayotte','Africa')-,('Mexico','MX','MEX','Mexico','North America')-,('Micronesia, Federated States of','FM','FSM','Micronesia','Oceania')-,('Moldova, Reworld of','MD','MDA','Moldova','Europe')-,('Monaco','MC','MCO','Monaco','Europe')-,('Mongolia','MN','MNG','Mongol Uls','Asia')-,('Albania','AL','ALB','Republika e Shqipërisë','Europe')-,('Montserrat','MS','MSR','Montserrat','North America')-,('Morocco','MA','MAR','Al-Maghrib','Africa')-,('Mozambique','MZ','MOZ','Mozambique','Africa')-,('Myanmar','MM','MMR','Myanma Pye','Asia')-,('Namibia','NA','NAM','Namibia','Africa')-,('Nauru','NR','NRU','Naoero/Nauru','Oceania')-,('Nepal','NP','NPL','Nepal','Asia')-,('Netherlands','NL','NLD','Nederland','Europe')-,('New Caledonia','NC','NCL','Nouvelle-Calédonie','Oceania')-,('New Zealand','NZ','NZL','New Zealand/Aotearoa','Oceania')-,('Nicaragua','NI','NIC','Nicaragua','North America')-,('Niger','NE','NER','Niger','Africa')-,('Nigeria','NG','NGA','Nigeria','Africa')-,('Niue','NU','NIU','Niue','Oceania')-,('Norfolk Island','NF','NFK','Norfolk Island','Oceania')-,('Northern Mariana Islands','MP','MNP','Northern Mariana Islands','Oceania')-,('Norway','NO','NOR','Norge','Europe')-,('Oman','OM','OMN','Oman','Asia')-,('Pakistan','PK','PAK','Pakistan','Asia')-,('Palau','PW','PLW','Belau/Palau','Oceania')-,('Palestine, State of','PS','PSE','Filastin','Asia')-,('Panama','PA','PAN','República de Panamá','North America')-,('Papua New Guinea','PG','PNG','Papua New Guinea/Papua Niugini','Oceania')-,('Paraguay','PY','PRY','Paraguay','South America')-,('Peru','PE','PER','Perú/Piruw','South America')-,('Philippines','PH','PHL','Pilipinas','Asia')-,('Pitcairn','PN','PCN','Pitcairn','Oceania')-,('Poland','PL','POL','Polska','Europe')-,('Portugal','PT','PRT','Portugal','Europe')-,('Puerto Rico','PR','PRI','Puerto Rico','North America')-,('Qatar','QA','QAT','Qatar','Asia')-,('Reunion','RE','REU','Reunion','Africa')-,('Romania','RO','ROM','Romania','Europe')-,('Russian Federation','RU','RUS','Rossija','Europe')-,('Rwanda','RW','RWA','Rwanda/Urwanda','Africa')-,('Saint Helena, Ascension and Tristan da Cunha','SH','SHN','Saint Helena','Africa')-,('Saint Kitts and Nevis','KN','KNA','Saint Kitts and Nevis','North America')-,('Saint Lucia','LC','LCA','Saint Lucia','North America')-,('Saint Pierre and Miquelon','PM','SPM','Saint-Pierre-et-Miquelon','North America')-,('Saint Vincent and the Grenadines','VC','VCT','Saint Vincent and the Grenadines','North America')-,('Samoa','WS','WSM','Samoa','Oceania')-,('San Marino','SM','SMR','San Marino','Europe')-,('Sao Tome and Principe','ST','STP','São Tomé e Príncipe','Africa')-,('Saudi Arabia','SA','SAU','Al-Mamlaka al-Arabiya as-Saudiya','Asia')-,('Senegal','SN','SEN','Sénégal/Sounougal','Africa')-,('Seychelles','SC','SYC','Sesel/Seychelles','Africa')-,('Sierra Leone','SL','SLE','Sierra Leone','Africa')-,('Singapore','SG','SGP','Singapore/Singapura/Xinjiapo/Singapur','Asia')-,('Slovakia','SK','SVK','Slovensko','Europe')-,('Slovenia','SI','SVN','Slovenija','Europe')-,('Solomon Islands','SB','SLB','Solomon Islands','Oceania')-,('Somalia','SO','SOM','Soomaaliya','Africa')-,('South Africa','ZA','ZAF','South Africa','Africa')-,('South Georgia and the South Sandwich Islands','GS','SGS','South Georgia and the South Sandwich Islands','Antarctica')-,('Spain','ES','ESP','España','Europe')-,('Sri Lanka','LK','LKA','Sri Lanka/Ilankai','Asia')-,('Sudan','SD','SDN','As-Sudan','Africa')-,('Suriname','SR','SUR','Suriname','South America')-,('Svalbard and Jan Mayen','SJ','SJM','Svalbard og Jan Mayen','Europe')-,('Swaziland','SZ','SWZ','kaNgwane','Africa')-,('Sweden','SE','SWE','Sverige','Europe')-,('Switzerland','CH','CHE','Schweiz/Suisse/Svizzera/Svizra','Europe')-,('Syrian Arab Reworld','SY','SYR','Suriya','Asia')-,('Taiwan (Province of China)','TW','TWN','Tai-wan','Asia')-,('Tajikistan','TJ','TJK','Tajikistan','Asia')-,('Tanzania, United Reworld of','TZ','TZA','Tanzania','Africa')-,('Thailand','TH','THA','Prathet Thai','Asia')-,('Togo','TG','TGO','Togo','Africa')-,('Tokelau','TK','TKL','Tokelau','Oceania')-,('Tonga','TO','TON','Tonga','Oceania')-,('Trinidad and Tobago','TT','TTO','Trinidad and Tobago','North America')-,('Tunisia','TN','TUN','Tunis/Tunisie','Africa')-,('Turkey','TR','TUR','Türkiye','Asia')-,('Turkmenistan','TM','TKM','Türkmenistan','Asia')-,('Turks and Caicos Islands','TC','TCA','The Turks and Caicos Islands','North America')-,('Tuvalu','TV','TUV','Tuvalu','Oceania')-,('Uganda','UG','UGA','Uganda','Africa')-,('Ukraine','UA','UKR','Ukrajina','Europe')-,('United Arab Emirates','AE','ARE','Al-Amirat al-Arabiya al-Muttahida','Asia')-,('United Kingdom','GB','GBR','United Kingdom','Europe')-,('United States','US','USA','United States','North America')-,('United States Minor Outlying Islands','UM','UMI','United States Minor Outlying Islands','Oceania')-,('Uruguay','UY','URY','Uruguay','South America')-,('Uzbekistan','UZ','UZB','Uzbekiston','Asia')-,('Vanuatu','VU','VUT','Vanuatu','Oceania')-,('Venezuela','VE','VEN','Venezuela','South America')-,('Viet Nam','VN','VNM','Viet Nam','Asia')-,('Virgin Islands (British)','VG','VGB','British Virgin Islands','North America')-,('Virgin Islands (U.S.)','VI','VIR','Virgin Islands of the United States','North America')-,('Wallis and Futuna','WF','WLF','Wallis-et-Futuna','Oceania')-,('Western Sahara','EH','ESH','As-Sahrawiya','Africa')-,('Yemen','YE','YEM','Al-Yaman','Asia')-,('Zambia','ZM','ZMB','Zambia','Africa')-,('Zimbabwe','ZW','ZWE','Zimbabwe','Africa')-,('Afghanistan','AF','AFG','Afganistan/Afqanestan','Asia')-,('Algeria','DZ','DZA','Al-Jazair/Algerie','Africa')-;+insert into public.countries (name,iso2,iso3,local_name,continent) values+ ('Bonaire, Sint Eustatius and Saba','BQ','BES',null,null),+ ('Curaçao','CW','CUW',null,null),+ ('Guernsey','GG','GGY',null,null),+ ('Isle of Man','IM','IMN',null,null),+ ('Jersey','JE','JEY',null,null),+ ('Åland Islands','AX','ALA',null,null),+ ('Montenegro','ME','MNE',null,null),+ ('Saint Barthélemy','BL','BLM',null,null),+ ('Saint Martin (French part)','MF','MAF',null,null),+ ('Serbia','RS','SRB',null,null),+ ('Sint Maarten (Dutch part)','SX','SXM',null,null),+ ('South Sudan','SS','SSD',null,null),+ ('Timor-Leste','TL','TLS',null,null),+ ('American Samoa','as','ASM','Amerika Samoa','Oceania'),+ ('Andorra','AD','AND','Andorra','Europe'),+ ('Angola','AO','AGO','Angola','Africa'),+ ('Anguilla','AI','AIA','Anguilla','North America'),+ ('Antarctica','AQ','ATA','','Antarctica'),+ ('Antigua and Barbuda','AG','ATG','Antigua and Barbuda','North America'),+ ('Argentina','AR','ARG','Argentina','South America'),+ ('Armenia','AM','ARM','Hajastan','Asia'),+ ('Aruba','AW','ABW','Aruba','North America'),+ ('Australia','AU','AUS','Australia','Oceania'),+ ('Austria','AT','AUT','Österreich','Europe'),+ ('Azerbaijan','AZ','AZE','Azerbaijan','Asia'),+ ('Bahamas','BS','BHS','The Bahamas','North America'),+ ('Bahrain','BH','BHR','Al-Bahrayn','Asia'),+ ('Bangladesh','BD','BGD','Bangladesh','Asia'),+ ('Barbados','BB','BRB','Barbados','North America'),+ ('Belarus','BY','BLR','Belarus','Europe'),+ ('Belgium','BE','BEL','Belgium/Belgique','Europe'),+ ('Belize','BZ','BLZ','Belize','North America'),+ ('Benin','BJ','BEN','Benin','Africa'),+ ('Bermuda','BM','BMU','Bermuda','North America'),+ ('Bhutan','BT','BTN','Druk-Yul','Asia'),+ ('Bolivia','BO','BOL','Bolivia','South America'),+ ('Bosnia and Herzegovina','BA','BIH','Bosna i Hercegovina','Europe'),+ ('Botswana','BW','BWA','Botswana','Africa'),+ ('Bouvet Island','BV','BVT','Bouvet Island','Antarctica'),+ ('Brazil','BR','BRA','Brasil','South America'),+ ('British Indian Ocean Territory','IO','IOT','British Indian Ocean Territory','Africa'),+ ('Brunei Darussalam','BN','BRN','Brunei Darussalam','Asia'),+ ('Bulgaria','BG','BGR','Balgarija','Europe'),+ ('Burkina Faso','BF','BFA','Burkina Faso','Africa'),+ ('Burundi','BI','BDI','Burundi/Uburundi','Africa'),+ ('Cambodia','KH','KHM','Cambodia','Asia'),+ ('Cameroon','CM','CMR','Cameroun/Cameroon','Africa'),+ ('Canada','CA','CAN','Canada','North America'),+ ('Cape Verde','CV','CPV','Cabo Verde','Africa'),+ ('Cayman Islands','KY','CYM','Cayman Islands','North America'),+ ('Central African Reworld','CF','CAF','Centrafrique','Africa'),+ ('Chad','TD','TCD','Tchad/Tshad','Africa'),+ ('Chile','CL','CHL','Chile','South America'),+ ('China','CN','CHN','Zhongquo','Asia'),+ ('Christmas Island','CX','CXR','Christmas Island','Oceania'),+ ('Cocos (Keeling) Islands','CC','CCK','Cocos (Keeling) Islands','Oceania'),+ ('Colombia','CO','COL','Colombia','South America'),+ ('Comoros','KM','COM','Komori/Comores','Africa'),+ ('Congo','CG','COG','Congo','Africa'),+ ('Congo, the Democratic Reworld of the','CD','COD','Republique Democratique du Congo','Africa'),+ ('Cook Islands','CK','COK','The Cook Islands','Oceania'),+ ('Costa Rica','CR','CRI','Costa Rica','North America'),+ ('Cote DIvoire','CI','CIV','Côte dIvoire','Africa'),+ ('Croatia','HR','HRV','Hrvatska','Europe'),+ ('Cuba','CU','CUB','Cuba','North America'),+ ('Cyprus','CY','CYP','Cyprus','Asia'),+ ('Czech Reworld','CZ','CZE','Czech','Europe'),+ ('Denmark','DK','DNK','Danmark','Europe'),+ ('Djibouti','DJ','DJI','Djibouti/Jibuti','Africa'),+ ('Dominica','DM','DMA','Dominica','North America'),+ ('Dominican Reworld','DO','DOM','Republica Dominicana','North America'),+ ('Ecuador','EC','ECU','Ecuador','South America'),+ ('Egypt','EG','EGY','Misr','Africa'),+ ('El Salvador','SV','SLV','El Salvador','North America'),+ ('Equatorial Guinea','GQ','GNQ','Guinea Ecuatorial','Africa'),+ ('Eritrea','ER','ERI','Ertra','Africa'),+ ('Estonia','EE','EST','Eesti','Europe'),+ ('Ethiopia','ET','ETH','Yeityopiya','Africa'),+ ('Falkland Islands (Malvinas)','FK','FLK','Falkland Islands','South America'),+ ('Faroe Islands','FO','FRO','Faroe Islands','Europe'),+ ('Fiji','FJ','FJI','Fiji Islands','Oceania'),+ ('Finland','FI','FIN','Suomi','Europe'),+ ('France','FR','FRA','France','Europe'),+ ('French Guiana','GF','GUF','Guyane francaise','South America'),+ ('French Polynesia','PF','PYF','Polynésie française','Oceania'),+ ('French Southern Territories','TF','ATF','Terres australes françaises','Antarctica'),+ ('Gabon','GA','GAB','Le Gabon','Africa'),+ ('Gambia','GM','GMB','The Gambia','Africa'),+ ('Georgia','GE','GEO','Sakartvelo','Asia'),+ ('Germany','DE','DEU','Deutschland','Europe'),+ ('Ghana','GH','GHA','Ghana','Africa'),+ ('Gibraltar','GI','GIB','Gibraltar','Europe'),+ ('Greece','GR','GRC','Greece','Europe'),+ ('Greenland','GL','GRL','Kalaallit Nunaat','North America'),+ ('Grenada','GD','GRD','Grenada','North America'),+ ('Guadeloupe','GP','GLP','Guadeloupe','North America'),+ ('Guam','GU','GUM','Guam','Oceania'),+ ('Guatemala','GT','GTM','Guatemala','North America'),+ ('Guinea','GN','GIN','Guinea','Africa'),+ ('Guinea-Bissau','GW','GNB','Guinea-Bissau','Africa'),+ ('Guyana','GY','GUY','Guyana','South America'),+ ('Haiti','HT','HTI','Haiti/Dayti','North America'),+ ('Heard Island and Mcdonald Islands','HM','HMD','Heard and McDonald Islands','Antarctica'),+ ('Holy See (Vatican City State)','VA','VAT','Santa Sede/Città del Vaticano','Europe'),+ ('Honduras','HN','HND','Honduras','North America'),+ ('Hong Kong','HK','HKG','Xianggang/Hong Kong','Asia'),+ ('Hungary','HU','HUN','Hungary','Europe'),+ ('Iceland','IS','ISL','Iceland','Europe'),+ ('India','IN','IND','Bharat/India','Asia'),+ ('Indonesia','ID','IDN','Indonesia','Asia'),+ ('Iran, Islamic Reworld of','IR','IRN','Iran','Asia'),+ ('Iraq','IQ','IRQ','Al-Irāq','Asia'),+ ('Ireland','IE','IRL','Ireland','Europe'),+ ('Israel','IL','ISR','Yisrael','Asia'),+ ('Italy','IT','ITA','Italia','Europe'),+ ('Jamaica','JM','JAM','Jamaica','North America'),+ ('Japan','JP','JPN','Nihon/Nippon','Asia'),+ ('Jordan','JO','JOR','Al-Urdunn','Asia'),+ ('Kazakhstan','KZ','KAZ','Qazaqstan','Asia'),+ ('Kenya','KE','KEN','Kenya','Africa'),+ ('Kiribati','KI','KIR','Kiribati','Oceania'),+ ('Korea, Democratic People''s Reworld of','KP','PRK','Choson Minjujuui Inmin Konghwaguk (Bukhan)','Asia'),+ ('Korea, Reworld of','KR','KOR','Taehan-minguk (Namhan)','Asia'),+ ('Kuwait','KW','KWT','Al-Kuwayt','Asia'),+ ('Kyrgyzstan','KG','KGZ','Kyrgyzstan','Asia'),+ ('Lao People''s Democratic Reworld','LA','LAO','Lao','Asia'),+ ('Latvia','LV','LVA','Latvija','Europe'),+ ('Lebanon','LB','LBN','Lubnan','Asia'),+ ('Lesotho','LS','LSO','Lesotho','Africa'),+ ('Liberia','LR','LBR','Liberia','Africa'),+ ('Libya','LY','LBY','Libiya','Africa'),+ ('Liechtenstein','LI','LIE','Liechtenstein','Europe'),+ ('Lithuania','LT','LTU','Lietuva','Europe'),+ ('Luxembourg','LU','LUX','Luxembourg','Europe'),+ ('Macao','MO','MAC','Macau/Aomen','Asia'),+ ('Macedonia, the Former Yugoslav Reworld of','MK','MKD','Makedonija','Europe'),+ ('Madagascar','MG','MDG','Madagasikara/Madagascar','Africa'),+ ('Malawi','MW','MWI','Malawi','Africa'),+ ('Malaysia','MY','MYS','Malaysia','Asia'),+ ('Maldives','MV','MDV','Dhivehi Raajje/Maldives','Asia'),+ ('Mali','ML','MLI','Mali','Africa'),+ ('Malta','MT','MLT','Malta','Europe'),+ ('Marshall Islands','MH','MHL','Marshall Islands/Majol','Oceania'),+ ('Martinique','MQ','MTQ','Martinique','North America'),+ ('Mauritania','MR','MRT','Muritaniya/Mauritanie','Africa'),+ ('Mauritius','MU','MUS','Mauritius','Africa'),+ ('Mayotte','YT','MYT','Mayotte','Africa'),+ ('Mexico','MX','MEX','Mexico','North America'),+ ('Micronesia, Federated States of','FM','FSM','Micronesia','Oceania'),+ ('Moldova, Reworld of','MD','MDA','Moldova','Europe'),+ ('Monaco','MC','MCO','Monaco','Europe'),+ ('Mongolia','MN','MNG','Mongol Uls','Asia'),+ ('Albania','AL','ALB','Republika e Shqipërisë','Europe'),+ ('Montserrat','MS','MSR','Montserrat','North America'),+ ('Morocco','MA','MAR','Al-Maghrib','Africa'),+ ('Mozambique','MZ','MOZ','Mozambique','Africa'),+ ('Myanmar','MM','MMR','Myanma Pye','Asia'),+ ('Namibia','NA','NAM','Namibia','Africa'),+ ('Nauru','NR','NRU','Naoero/Nauru','Oceania'),+ ('Nepal','NP','NPL','Nepal','Asia'),+ ('Netherlands','NL','NLD','Nederland','Europe'),+ ('New Caledonia','NC','NCL','Nouvelle-Calédonie','Oceania'),+ ('New Zealand','NZ','NZL','New Zealand/Aotearoa','Oceania'),+ ('Nicaragua','NI','NIC','Nicaragua','North America'),+ ('Niger','NE','NER','Niger','Africa'),+ ('Nigeria','NG','NGA','Nigeria','Africa'),+ ('Niue','NU','NIU','Niue','Oceania'),+ ('Norfolk Island','NF','NFK','Norfolk Island','Oceania'),+ ('Northern Mariana Islands','MP','MNP','Northern Mariana Islands','Oceania'),+ ('Norway','NO','NOR','Norge','Europe'),+ ('Oman','OM','OMN','Oman','Asia'),+ ('Pakistan','PK','PAK','Pakistan','Asia'),+ ('Palau','PW','PLW','Belau/Palau','Oceania'),+ ('Palestine, State of','PS','PSE','Filastin','Asia'),+ ('Panama','PA','PAN','República de Panamá','North America'),+ ('Papua New Guinea','PG','PNG','Papua New Guinea/Papua Niugini','Oceania'),+ ('Paraguay','PY','PRY','Paraguay','South America'),+ ('Peru','PE','PER','Perú/Piruw','South America'),+ ('Philippines','PH','PHL','Pilipinas','Asia'),+ ('Pitcairn','PN','PCN','Pitcairn','Oceania'),+ ('Poland','PL','POL','Polska','Europe'),+ ('Portugal','PT','PRT','Portugal','Europe'),+ ('Puerto Rico','PR','PRI','Puerto Rico','North America'),+ ('Qatar','QA','QAT','Qatar','Asia'),+ ('Reunion','RE','REU','Reunion','Africa'),+ ('Romania','RO','ROM','Romania','Europe'),+ ('Russian Federation','RU','RUS','Rossija','Europe'),+ ('Rwanda','RW','RWA','Rwanda/Urwanda','Africa'),+ ('Saint Helena, Ascension and Tristan da Cunha','SH','SHN','Saint Helena','Africa'),+ ('Saint Kitts and Nevis','KN','KNA','Saint Kitts and Nevis','North America'),+ ('Saint Lucia','LC','LCA','Saint Lucia','North America'),+ ('Saint Pierre and Miquelon','PM','SPM','Saint-Pierre-et-Miquelon','North America'),+ ('Saint Vincent and the Grenadines','VC','VCT','Saint Vincent and the Grenadines','North America'),+ ('Samoa','WS','WSM','Samoa','Oceania'),+ ('San Marino','SM','SMR','San Marino','Europe'),+ ('Sao Tome and Principe','ST','STP','São Tomé e Príncipe','Africa'),+ ('Saudi Arabia','SA','SAU','Al-Mamlaka al-Arabiya as-Saudiya','Asia'),+ ('Senegal','SN','SEN','Sénégal/Sounougal','Africa'),+ ('Seychelles','SC','SYC','Sesel/Seychelles','Africa'),+ ('Sierra Leone','SL','SLE','Sierra Leone','Africa'),+ ('Singapore','SG','SGP','Singapore/Singapura/Xinjiapo/Singapur','Asia'),+ ('Slovakia','SK','SVK','Slovensko','Europe'),+ ('Slovenia','SI','SVN','Slovenija','Europe'),+ ('Solomon Islands','SB','SLB','Solomon Islands','Oceania'),+ ('Somalia','SO','SOM','Soomaaliya','Africa'),+ ('South Africa','ZA','ZAF','South Africa','Africa'),+ ('South Georgia and the South Sandwich Islands','GS','SGS','South Georgia and the South Sandwich Islands','Antarctica'),+ ('Spain','ES','ESP','España','Europe'),+ ('Sri Lanka','LK','LKA','Sri Lanka/Ilankai','Asia'),+ ('Sudan','SD','SDN','As-Sudan','Africa'),+ ('Suriname','SR','SUR','Suriname','South America'),+ ('Svalbard and Jan Mayen','SJ','SJM','Svalbard og Jan Mayen','Europe'),+ ('Swaziland','SZ','SWZ','kaNgwane','Africa'),+ ('Sweden','SE','SWE','Sverige','Europe'),+ ('Switzerland','CH','CHE','Schweiz/Suisse/Svizzera/Svizra','Europe'),+ ('Syrian Arab Reworld','SY','SYR','Suriya','Asia'),+ ('Taiwan (Province of China)','TW','TWN','Tai-wan','Asia'),+ ('Tajikistan','TJ','TJK','Tajikistan','Asia'),+ ('Tanzania, United Reworld of','TZ','TZA','Tanzania','Africa'),+ ('Thailand','TH','THA','Prathet Thai','Asia'),+ ('Togo','TG','TGO','Togo','Africa'),+ ('Tokelau','TK','TKL','Tokelau','Oceania'),+ ('Tonga','TO','TON','Tonga','Oceania'),+ ('Trinidad and Tobago','TT','TTO','Trinidad and Tobago','North America'),+ ('Tunisia','TN','TUN','Tunis/Tunisie','Africa'),+ ('Turkey','TR','TUR','Türkiye','Asia'),+ ('Turkmenistan','TM','TKM','Türkmenistan','Asia'),+ ('Turks and Caicos Islands','TC','TCA','The Turks and Caicos Islands','North America'),+ ('Tuvalu','TV','TUV','Tuvalu','Oceania'),+ ('Uganda','UG','UGA','Uganda','Africa'),+ ('Ukraine','UA','UKR','Ukrajina','Europe'),+ ('United Arab Emirates','AE','ARE','Al-Amirat al-Arabiya al-Muttahida','Asia'),+ ('United Kingdom','GB','GBR','United Kingdom','Europe'),+ ('United States','US','USA','United States','North America'),+ ('United States Minor Outlying Islands','UM','UMI','United States Minor Outlying Islands','Oceania'),+ ('Uruguay','UY','URY','Uruguay','South America'),+ ('Uzbekistan','UZ','UZB','Uzbekiston','Asia'),+ ('Vanuatu','VU','VUT','Vanuatu','Oceania'),+ ('Venezuela','VE','VEN','Venezuela','South America'),+ ('Viet Nam','VN','VNM','Viet Nam','Asia'),+ ('Virgin Islands (British)','VG','VGB','British Virgin Islands','North America'),+ ('Virgin Islands (U.S.)','VI','VIR','Virgin Islands of the United States','North America'),+ ('Wallis and Futuna','WF','WLF','Wallis-et-Futuna','Oceania'),+ ('Western Sahara','EH','ESH','As-Sahrawiya','Africa'),+ ('Yemen','YE','YEM','Al-Yaman','Asia'),+ ('Zambia','ZM','ZMB','Zambia','Africa'),+ ('Zimbabwe','ZW','ZWE','Zimbabwe','Africa'),+ ('Afghanistan','AF','AFG','Afganistan/Afqanestan','Asia'),+ ('Algeria','DZ','DZA','Al-Jazair/Algerie','Africa');`.trim(),},{@@ -472,64 +474,91 @@ create function public.authorize(requested_permission app_permission,user_id uuid)-returns boolean as $$-declare- bind_permissions int;-begin- select count(*)- from public.role_permissions- inner join public.user_roles on role_permissions.role = user_roles.role- where role_permissions.permission = authorize.requested_permission- and user_roles.user_id = authorize.user_id- into bind_permissions;-- return bind_permissions > 0;-end;-$$ language plpgsql security definer;+returns boolean as+$$+ declare+ bind_permissions int;+ begin+ select+ count(*)+ from public.role_permissions+ inner join public.user_roles on role_permissions.role = user_roles.role+ where+ role_permissions.permission = authorize.requested_permission and+ user_roles.user_id = authorize.user_id+ into bind_permissions;++ return bind_permissions > 0;+ end;+$$+language plpgsql security definer;-- Secure the tables-alter table public.users enable row level security;-alter table public.channels enable row level security;-alter table public.messages enable row level security;-alter table public.user_roles enable row level security;-alter table public.role_permissions enable row level security;-create policy "Allow logged-in read access" on public.users for select using ( auth.role() = 'authenticated' );-create policy "Allow individual insert access" on public.users for insert with check ( auth.uid() = id );-create policy "Allow individual update access" on public.users for update using ( auth.uid() = id );-create policy "Allow logged-in read access" on public.channels for select using ( auth.role() = 'authenticated' );-create policy "Allow individual insert access" on public.channels for insert with check ( auth.uid() = created_by );-create policy "Allow individual delete access" on public.channels for delete using ( auth.uid() = created_by );-create policy "Allow authorized delete access" on public.channels for delete using ( authorize('channels.delete', auth.uid()) );-create policy "Allow logged-in read access" on public.messages for select using ( auth.role() = 'authenticated' );-create policy "Allow individual insert access" on public.messages for insert with check ( auth.uid() = user_id );-create policy "Allow individual update access" on public.messages for update using ( auth.uid() = user_id );-create policy "Allow individual delete access" on public.messages for delete using ( auth.uid() = user_id );-create policy "Allow authorized delete access" on public.messages for delete using ( authorize('messages.delete', auth.uid()) );-create policy "Allow individual read access" on public.user_roles for select using ( auth.uid() = user_id );---- Send "previous data" on change-alter table public.users replica identity full;-alter table public.channels replica identity full;-alter table public.messages replica identity full;+alter table public.users+ enable row level security;+alter table public.channels+ enable row level security;+alter table public.messages+ enable row level security;+alter table public.user_roles+ enable row level security;+alter table public.role_permissions+ enable row level security;++create policy "Allow logged-in read access" on public.users+ for select using (auth.role() = 'authenticated');+create policy "Allow individual insert access" on public.users+ for insert with check (auth.uid() = id);+create policy "Allow individual update access" on public.users+ for update using ( auth.uid() = id );+create policy "Allow logged-in read access" on public.channels+ for select using (auth.role() = 'authenticated');+create policy "Allow individual insert access" on public.channels+ for insert with check (auth.uid() = created_by);+create policy "Allow individual delete access" on public.channels+ for delete using (auth.uid() = created_by);+create policy "Allow authorized delete access" on public.channels+ for delete using (authorize('channels.delete', auth.uid()));+create policy "Allow logged-in read access" on public.messages+ for select using (auth.role() = 'authenticated');+create policy "Allow individual insert access" on public.messages+ for insert with check (auth.uid() = user_id);+create policy "Allow individual update access" on public.messages+ for update using (auth.uid() = user_id);+create policy "Allow individual delete access" on public.messages+ for delete using (auth.uid() = user_id);+create policy "Allow authorized delete access" on public.messages+ for delete using (authorize('messages.delete', auth.uid()));+create policy "Allow individual read access" on public.user_roles+ for select using (auth.uid() = user_id);++-- Send "previous data" on change+alter table public.users+ replica identity full;+alter table public.channels+ replica identity full;+alter table public.messages+ replica identity full;-- inserts a row into public.users and assigns roles-create function public.handle_new_user()-returns trigger as $$-declare is_admin boolean;-begin- insert into public.users (id, username)- values (new.id, new.email);-- select count(*) = 1 from auth.users into is_admin;-- if position('+supaadmin@' in new.email) > 0 then- insert into public.user_roles (user_id, role) values (new.id, 'admin');- elsif position('+supamod@' in new.email) > 0 then- insert into public.user_roles (user_id, role) values (new.id, 'moderator');- end if;-- return new;-end;+create function public.handle_new_user()+returns trigger as+$$+ declare is_admin boolean;+ begin+ insert into public.users (id, username)+ values (new.id, new.email);++ select count(*) = 1 from auth.users into is_admin;++ if position('+supaadmin@' in new.email) > 0 then+ insert into public.user_roles (user_id, role) values (new.id, 'admin');+ elsif position('+supamod@' in new.email) > 0 then+ insert into public.user_roles (user_id, role) values (new.id, 'moderator');+ end if;++ return new;+ end;$$ language plpgsql security definer;-- trigger the function every time a user is created@@ -542,12 +571,12 @@ create trigger on_auth_user_created* Only allow realtime listening on public tables.*/-begin;+begin;-- remove the realtime publication- drop publication if exists supabase_realtime;+ drop publication if exists supabase_realtime;-- re-create the publication but don't enable it for any tables- create publication supabase_realtime;+ create publication supabase_realtime;commit;-- add tables to the publication@@ -569,12 +598,12 @@ insert into public.messages (message, channel_id, user_id)values('Hello World 👋', 1, '8d0fd2b3-9ca7-4d9e-a95f-9e13dded323e'),('Perfection is attained, not when there is nothing more to add, but when there is nothing left to take away.', 2, '8d0fd2b3-9ca7-4d9e-a95f-9e13dded323e');-+insert into public.role_permissions (role, permission)values('admin', 'channels.delete'),('admin', 'messages.delete'),- ('moderator', 'messages.delete');+ ('moderator', 'messages.delete');`.trim(),},{@@ -584,11 +613,11 @@ valuesdescription: 'Build a basic todo list with Row Level Security.',sql: `----- For use with:+-- For use with:-- https://github.com/supabase/supabase/tree/master/examples/nextjs-todo-list or-- https://github.com/supabase/supabase/tree/master/examples/react-todo-list or-- https://github.com/supabase/supabase/tree/master/examples/sveltejs-todo-list or--- https://github.com/supabase/supabase/tree/master/examples/vue3-ts-todo-list+-- https://github.com/supabase/supabase/tree/master/examples/vue3-ts-todo-list--create table todos (@@ -598,20 +627,15 @@ create table todos (is_complete boolean default false,inserted_at timestamp with time zone default timezone('utc'::text, now()) not null);-alter table todos enable row level security;-create policy "Individuals can create todos." on todos forinsert with check (auth.uid() = user_id);-create policy "Individuals can view their own todos. " on todos forselect using (auth.uid() = user_id);-create policy "Individuals can update their own todos." on todos forupdate using (auth.uid() = user_id);-create policy "Individuals can delete their own todos." on todos for- delete using (auth.uid() = user_id);+ delete using (auth.uid() = user_id);`.trim(),},{@@ -620,7 +644,7 @@ create policy "Individuals can delete their own todos." on todos fortitle: 'Stripe Subscriptions',description: 'Starter template for the Next.js Stripe Subscriptions Starter.',sql: `-/**+/*** USERS* Note: This table contains user data. Users should only be able to view and update their own data.*/@@ -634,24 +658,31 @@ create table users (-- Stores your customer's payment instruments.payment_method jsonb);-alter table users enable row level security;-create policy "Can view own user data." on users for select using (auth.uid() = id);-create policy "Can update own user data." on users for update using (auth.uid() = id);+alter table users+ enable row level security;+create policy "Can view own user data." on users+ for select using (auth.uid() = id);+create policy "Can update own user data." on users+ for update using (auth.uid() = id);/*** This trigger automatically creates a user entry when a new user signs up via Supabase Auth.-*/-create function public.handle_new_user()-returns trigger as $$-begin- insert into public.users (id, full_name, avatar_url)- values (new.id, new.raw_user_meta_data->>'full_name', new.raw_user_meta_data->>'avatar_url');- return new;-end;-$$ language plpgsql security definer;+*/+create function public.handle_new_user()+returns trigger as+$$+ begin+ insert into public.users (id, full_name, avatar_url)+ values (new.id, new.raw_user_meta_data->>'full_name', new.raw_user_meta_data->>'avatar_url');+ return new;+ end;+$$+language plpgsql security definer;+create trigger on_auth_user_createdafter insert on auth.users- for each row execute procedure public.handle_new_user();+ for each row+ execute procedure public.handle_new_user();/*** CUSTOMERS@@ -666,7 +697,7 @@ create table customers (alter table customers enable row level security;-- No policies as this is a private table that the user must not have access to.-/**+/*** PRODUCTS* Note: products are created and managed in Stripe and synced to our DB via Stripe webhooks.*/@@ -684,8 +715,10 @@ create table products (-- Set of key-value pairs, used to store additional information about the object in a structured format.metadata jsonb);-alter table products enable row level security;-create policy "Allow public read-only access." on products for select using (true);+alter table products+ enable row level security;+create policy "Allow public read-only access." on products+ for select using (true);/*** PRICES@@ -697,7 +730,7 @@ create table prices (-- Price ID from Stripe, e.g. price_1234.id text primary key,-- The ID of the prduct that this price belongs to.- product_id text references products,+ product_id text references products,-- Whether the price can be used for new purchases.active boolean,-- A brief description of the price.@@ -717,8 +750,10 @@ create table prices (-- Set of key-value pairs, used to store additional information about the object in a structured format.metadata jsonb);-alter table prices enable row level security;-create policy "Allow public read-only access." on prices for select using (true);+alter table prices+ enable row level security;+create policy "Allow public read-only access." on prices+ for select using (true);/*** SUBSCRIPTIONS@@ -756,15 +791,18 @@ create table subscriptions (-- If the subscription has a trial, the end of that trial.trial_end timestamp with time zone default timezone('utc'::text, now()));-alter table subscriptions enable row level security;-create policy "Can only view own subs data." on subscriptions for select using (auth.uid() = user_id);+alter table subscriptions+ enable row level security;+create policy "Can only view own subs data." on subscriptions+ for select using (auth.uid() = user_id);/*** REALTIME SUBSCRIPTIONS* Only allow realtime listening on public tables.*/drop publication if exists supabase_realtime;-create publication supabase_realtime for table products, prices;+create publication supabase_realtime+ for table products, prices;`.trim(),},{@@ -786,42 +824,38 @@ create table profiles (constraint username_length check (char_length(username) >= 3));-alter table profiles enable row level security;+alter table profiles+ enable row level security;-create policy "Public profiles are viewable by everyone."- on profiles for select- using ( true );+create policy "Public profiles are viewable by everyone." on profiles+ for select using (true);-create policy "Users can insert their own profile."- on profiles for insert- with check ( auth.uid() = id );+create policy "Users can insert their own profile." on profiles+ for insert with check (auth.uid() = id);-create policy "Users can update own profile."- on profiles for update- using ( auth.uid() = id );+create policy "Users can update own profile." on profiles+ for update using (auth.uid() = id);-- Set up Realtime!begin;drop publication if exists supabase_realtime;create publication supabase_realtime;commit;-alter publication supabase_realtime add table profiles;+alter publication supabase_realtime+ add table profiles;-- Set up Storage!insert into storage.buckets (id, name)-values ('avatars', 'avatars');+ values ('avatars', 'avatars');-create policy "Avatar images are publicly accessible."- on storage.objects for select- using ( bucket_id = 'avatars' );+create policy "Avatar images are publicly accessible." on storage.objects+ for select using (bucket_id = 'avatars');-create policy "Anyone can upload an avatar."- on storage.objects for insert- with check ( bucket_id = 'avatars' );+create policy "Anyone can upload an avatar." on storage.objects+ for insert with check (bucket_id = 'avatars');-create policy "Anyone can update an avatar."- on storage.objects for update- with check ( bucket_id = 'avatars' );+create policy "Anyone can update an avatar." on storage.objects+ for update with check (bucket_id = 'avatars');`.trim(),},]diff --git a/studio/pages/api/projects/[ref]/content.ts b/studio/pages/api/projects/[ref]/content.tsindex 710845e1bf2..01206f4f68f 100644--- a/studio/pages/api/projects/[ref]/content.ts+++ b/studio/pages/api/projects/[ref]/content.ts@@ -32,9 +32,9 @@ const handleGetAll = async (req: NextApiRequest, res: NextApiResponse) => {visibility: 'user',content: {content_id: '1.0',- sql: `SELECT * FROM-(SELECT version()) "version",-(SELECT current_setting('server_version_num') AS version_number) version_number;`,+ sql: `select * from+ (select version()) as version,+ (select current_setting('server_version_num')) as version_number;`,schema_version: '1',favorite: false,},