diff --git a/README.md b/README.md index d7fbaa5..9c9b470 100644 --- a/README.md +++ b/README.md @@ -130,3 +130,7 @@ various tables, not just the columns listed here. 6. What SQL keywords or concept would you use if you wanted to automatically delete all messages by a user if that user were deleted from the `user` table? + + I think it is CASCADE... + +* Initial commit \ No newline at end of file diff --git a/alice_channel.txt b/alice_channel.txt new file mode 100644 index 0000000..1a61551 --- /dev/null +++ b/alice_channel.txt @@ -0,0 +1,4 @@ +name +---------- +#general +#random diff --git a/all_channel.txt b/all_channel.txt new file mode 100644 index 0000000..78bc329 --- /dev/null +++ b/all_channel.txt @@ -0,0 +1,4 @@ +id name organization_id created_at updated_at +---------- ---------- --------------- ------------------- ------------------- +1 #general 1 2018-09-07 17:12:34 2018-09-07 17:12:34 +2 #random 1 2018-09-07 17:12:34 2018-09-07 17:12:34 diff --git a/all_channel_from_lambda.txt b/all_channel_from_lambda.txt new file mode 100644 index 0000000..1a61551 --- /dev/null +++ b/all_channel_from_lambda.txt @@ -0,0 +1,4 @@ +name +---------- +#general +#random diff --git a/all_general_message.txt b/all_general_message.txt new file mode 100644 index 0000000..9e567bd --- /dev/null +++ b/all_general_message.txt @@ -0,0 +1,6 @@ +id content user_id channel_id post_time update_post id name organization_id created_at updated_at +---------- ----------------- ---------- ---------- ------------------- ------------------- ---------- ---------- --------------- ------------------- ------------------- +1 first from alice 1 1 2018-09-07 17:51:52 2018-09-07 17:51:52 1 #general 1 2018-09-07 17:39:21 2018-09-07 17:39:21 +4 first from bob 2 1 2018-09-07 17:51:52 2018-09-07 17:51:52 1 #general 1 2018-09-07 17:39:21 2018-09-07 17:39:21 +7 first from chris 3 1 2018-09-07 17:51:52 2018-09-07 17:51:52 1 #general 1 2018-09-07 17:39:21 2018-09-07 17:39:21 +8 second from chris 3 1 2018-09-07 17:51:52 2018-09-07 17:51:52 1 #general 1 2018-09-07 17:39:21 2018-09-07 17:39:21 diff --git a/all_organization.txt b/all_organization.txt new file mode 100644 index 0000000..521a4f5 --- /dev/null +++ b/all_organization.txt @@ -0,0 +1,3 @@ +id name created_at +---------- ------------- ------------------- +1 Lambda School 2018-09-07 17:12:34 diff --git a/all_user_in_general_channel.txt b/all_user_in_general_channel.txt new file mode 100644 index 0000000..d53c3f5 --- /dev/null +++ b/all_user_in_general_channel.txt @@ -0,0 +1,4 @@ +name +---------- +Alice +Bob diff --git a/all_users_messages_count.txt b/all_users_messages_count.txt new file mode 100644 index 0000000..a06d4e6 --- /dev/null +++ b/all_users_messages_count.txt @@ -0,0 +1,5 @@ +User Name Message Count +---------- ------------- +Chris 4 +Bob 3 +Alice 3 diff --git a/queries.sql b/queries.sql new file mode 100644 index 0000000..be4dcc8 --- /dev/null +++ b/queries.sql @@ -0,0 +1,59 @@ +CREATE TABLE organization( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name VARCHAR(128) NOT NULL UNIQUE, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE channel( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name VARCHAR(128) NOT NULL UNIQUE, + organization_id INTEGER REFERENCES organization(id), + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE user( + id INTEGER PRIMARY KEY AUTOINCREMENT, + name VARCHAR(128) NOT NULL UNIQUE +); + +CREATE TABLE user_channel( + user_id INTEGER REFERENCES user(id), + channel_id INTEGER REFERENCES channel(id) +); + +CREATE TABLE message( + id INTEGER PRIMARY KEY AUTOINCREMENT, + content TEXT, + user_id INTEGER REFERENCES user(id), + channel_id INTEGER REFERENCES channel(id), + post_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + update_post TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + +INSERT INTO organization (name) VALUES ("Lambda School"); + +INSERT INTO user (name) VALUES ("Alice"); +INSERT INTO user (name) VALUES ("Bob"); +INSERT INTO user (name) VALUES ("Chris"); + +INSERT INTO channel (name, organization_id) VALUES ("#general", 1); +INSERT INTO channel (name, organization_id) VALUES ("#random", 1); + +INSERT INTO user_channel (user_id, channel_id) VALUES (1, 1); +INSERT INTO user_channel (user_id, channel_id) VALUES (1, 2); +INSERT INTO user_channel (user_id, channel_id) VALUES (2, 1); +INSERT INTO user_channel (user_id, channel_id) VALUES (3, 2); + +INSERT INTO message (content, user_id, channel_id) VALUES ("first from alice", 1, 1); +INSERT INTO message (content, user_id, channel_id) VALUES ("second from alice", 1, 2); +INSERT INTO message (content, user_id, channel_id) VALUES ("third from alice", 1, 2); + +INSERT INTO message (content, user_id, channel_id) VALUES ("first from bob", 2, 1); +INSERT INTO message (content, user_id, channel_id) VALUES ("second from bob", 2, 2); +INSERT INTO message (content, user_id, channel_id) VALUES ("third from bob", 2, 2); + +INSERT INTO message (content, user_id, channel_id) VALUES ("first from chris", 3, 1); +INSERT INTO message (content, user_id, channel_id) VALUES ("second from chris", 3, 1); +INSERT INTO message (content, user_id, channel_id) VALUES ("third from chris", 3, 2); +INSERT INTO message (content, user_id, channel_id) VALUES ("forth from chris", 3, 2); \ No newline at end of file diff --git a/test.db b/test.db new file mode 100644 index 0000000..dba7b27 Binary files /dev/null and b/test.db differ