Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions alice_channel.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name
----------
#general
#random
4 changes: 4 additions & 0 deletions all_channel.txt
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions all_channel_from_lambda.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name
----------
#general
#random
6 changes: 6 additions & 0 deletions all_general_message.txt
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions all_organization.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id name created_at
---------- ------------- -------------------
1 Lambda School 2018-09-07 17:12:34
4 changes: 4 additions & 0 deletions all_user_in_general_channel.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name
----------
Alice
Bob
5 changes: 5 additions & 0 deletions all_users_messages_count.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
User Name Message Count
---------- -------------
Chris 4
Bob 3
Alice 3
59 changes: 59 additions & 0 deletions queries.sql
Original file line number Diff line number Diff line change
@@ -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);
Binary file added test.db
Binary file not shown.