-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
72 additions
and
38 deletions.
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -3,42 +3,48 @@ INSERT INTO address { | |
number: '221B', | ||
street: 'Baker street', | ||
city: 'London', | ||
country: 'UK' | ||
country: 'UK', | ||
customer: customer:pratim | ||
}; | ||
|
||
INSERT INTO customer { | ||
id: 'pratim', | ||
name: 'Pratim', | ||
email: '[email protected]', | ||
address: address:pratim_home | ||
password: '12345678', | ||
addresses: [address:pratim_home] | ||
}; | ||
|
||
INSERT INTO address { | ||
id: 'tobie_home', | ||
number: '221A', | ||
street: 'Church street', | ||
city: 'London', | ||
country: 'UK' | ||
country: 'UK', | ||
customer: customer:tobie | ||
}; | ||
|
||
INSERT INTO customer { | ||
id: 'tobie', | ||
name: 'Tobie', | ||
email: '[email protected]', | ||
address: address:tobie_home | ||
password: '12345678', | ||
addresses: [address:tobie_home] | ||
}; | ||
|
||
INSERT INTO address { | ||
id: 'alex_home', | ||
number: '221C', | ||
street: 'Pound street', | ||
city: 'London', | ||
country: 'UK' | ||
country: 'UK', | ||
customer: customer:alex | ||
}; | ||
|
||
INSERT INTO customer { | ||
id: 'alex', | ||
name: 'Alex', | ||
email: '[email protected]', | ||
address: address:alex_home | ||
password: '12345678', | ||
addresses: [address:alex_home] | ||
}; |
10 changes: 5 additions & 5 deletions
10
templates/ecommerce/migrations/YYYYMMDD_HHMM03_PurchaseProducts.surql
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
2 changes: 1 addition & 1 deletion
2
templates/ecommerce/migrations/down/YYYYMMDD_HHMM03_PurchaseProducts.surql
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 |
---|---|---|
@@ -1 +1 @@ | ||
DELETE purchased; | ||
DELETE purchases; |
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
DEFINE TABLE address SCHEMALESS; | ||
DEFINE TABLE address SCHEMALESS | ||
PERMISSIONS | ||
FOR select, create, update, delete WHERE customer = $auth.id; | ||
|
||
DEFINE FIELD number ON address TYPE string; | ||
DEFINE FIELD street ON address TYPE string; | ||
DEFINE FIELD city ON address TYPE string; | ||
DEFINE FIELD state ON address TYPE string; | ||
DEFINE FIELD zip_code ON address TYPE string; | ||
DEFINE FIELD country ON address TYPE string; | ||
DEFINE FIELD country ON address TYPE string; | ||
DEFINE FIELD customer ON address TYPE record(customer); |
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 |
---|---|---|
@@ -1,5 +1,28 @@ | ||
DEFINE TABLE customer SCHEMALESS; | ||
DEFINE TABLE customer SCHEMALESS | ||
PERMISSIONS | ||
FOR select FULL | ||
FOR update WHERE id = $auth.id | ||
FOR create, delete NONE; | ||
|
||
DEFINE FIELD name ON customer TYPE string; | ||
DEFINE FIELD email ON customer TYPE string; | ||
DEFINE FIELD address ON customer TYPE record(address); | ||
DEFINE FIELD password ON customer TYPE string ASSERT $value != NONE; | ||
DEFINE FIELD addresses ON customer TYPE array; | ||
DEFINE FIELD addresses.* ON customer TYPE record(address); | ||
|
||
DEFINE INDEX unique_email ON customer COLUMNS email UNIQUE; | ||
|
||
DEFINE SCOPE customer_scope | ||
SESSION 30d | ||
SIGNUP ( | ||
CREATE customer | ||
SET | ||
name = $name, | ||
email = $email, | ||
password = crypto::argon2::generate($password) | ||
) | ||
SIGNIN ( | ||
SELECT * | ||
FROM customer | ||
WHERE email = $email AND crypto::argon2::compare(password, $password) | ||
); |
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 |
---|---|---|
@@ -1,7 +1,11 @@ | ||
DEFINE TABLE product SCHEMALESS; | ||
DEFINE TABLE product SCHEMALESS | ||
PERMISSIONS | ||
FOR select FULL | ||
FOR create, update, delete NONE; | ||
|
||
DEFINE FIELD name ON product TYPE string; | ||
DEFINE FIELD description ON product TYPE string; | ||
DEFINE FIELD price ON product TYPE number; | ||
DEFINE FIELD category ON product TYPE string; | ||
DEFINE FIELD images ON product TYPE array; | ||
DEFINE FIELD images ON product TYPE array; | ||
DEFINE FIELD images.* ON product TYPE string; |
This file was deleted.
Oops, something went wrong.
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,13 @@ | ||
# in: customer | ||
# out: product | ||
DEFINE TABLE purchases SCHEMALESS | ||
PERMISSIONS | ||
FOR select WHERE in = $auth.id | ||
FOR create, update, delete NONE; | ||
|
||
DEFINE FIELD quantity ON purchases TYPE number; | ||
DEFINE FIELD shipping_address ON purchases TYPE record(address); | ||
DEFINE FIELD created_at ON purchases TYPE datetime VALUE $before OR time::now(); | ||
DEFINE FIELD shipped_at ON purchases TYPE datetime; | ||
DEFINE FIELD total ON purchases TYPE number; | ||
DEFINE FIELD status ON purchases TYPE string VALUE $value OR $before OR 'Pending' ASSERT $value == NONE OR $value INSIDE ['Pending', 'Delivered']; |