database-design

How to store a store opening hours in an SQL database?

戏子无情 提交于 2020-12-08 05:11:58
问题 I am developing an app for stores (in fact, restaurants) and need to design the PostgreSQL data structure for it. For instance, the restaurant might have opening hours Mon-Fri from 7:30 to 17:00 and from 20:30 to 1:00 the following day. The data to be stored for each weekday would be something like ['Monday', true, 450, 1050, 1230, 1500 ] , being true === "it does open on Mondays", 450, opening time is 450 minutes past midnight (see here), i.e. at 7:30h, closes at 17:30h, reopens at 20:30h,

PostgreSQL Trigger after update of a specific column

我的未来我决定 提交于 2020-12-05 09:14:41
问题 I'm on my way of exploring triggers and want to create one that fires after an Update event on a game_saved column. As I have read in PostgreSQL docs it is possible to create triggers for columns. The column contains boolean values so the user may either add game to his collection or remove it. So I want the trigger function to calculate the number of games set to TRUE in the game_saved column for a certain user. And then update total_game_count in a game_collection table. game_collection id

MongoDB : How to design schema based on application access patterns?

徘徊边缘 提交于 2020-12-04 12:00:09
问题 As someone that comes from DynamoDB, modeling a MongoDB schema to really fit deeply into my application is kinda confusing, specially since it has the concept of references and from what I read is not recommended to keep duplicated data to accomodate your queries. Take the following example (modeled in mongoengine, but shouldn't matter) : #User class User(Document): email = EmailFieldprimary_key=True) pswd_hash = StringField() #This also makes it easier to find the Projects the user has a

MongoDB : How to design schema based on application access patterns?

对着背影说爱祢 提交于 2020-12-04 11:59:45
问题 As someone that comes from DynamoDB, modeling a MongoDB schema to really fit deeply into my application is kinda confusing, specially since it has the concept of references and from what I read is not recommended to keep duplicated data to accomodate your queries. Take the following example (modeled in mongoengine, but shouldn't matter) : #User class User(Document): email = EmailFieldprimary_key=True) pswd_hash = StringField() #This also makes it easier to find the Projects the user has a

MongoDB : How to design schema based on application access patterns?

戏子无情 提交于 2020-12-04 11:59:27
问题 As someone that comes from DynamoDB, modeling a MongoDB schema to really fit deeply into my application is kinda confusing, specially since it has the concept of references and from what I read is not recommended to keep duplicated data to accomodate your queries. Take the following example (modeled in mongoengine, but shouldn't matter) : #User class User(Document): email = EmailFieldprimary_key=True) pswd_hash = StringField() #This also makes it easier to find the Projects the user has a

How to structure database for unread item alerts per user

匆匆过客 提交于 2020-11-30 12:41:02
问题 I just have a general database theory question. I have a need to make something similar to showing what posts/items a user has viewed or not (such as in a forum) or an unread email message. What I have is there are posts that multiple users can view, but it needs to separate by user who has actually viewed it. So if User A viewed Post 1, it would no longer show that Post 1 is a new item to view, but to User B, it would still show that Post 1 is a new item to view. I've search for other ideas

How to structure database for unread item alerts per user

旧城冷巷雨未停 提交于 2020-11-30 12:40:26
问题 I just have a general database theory question. I have a need to make something similar to showing what posts/items a user has viewed or not (such as in a forum) or an unread email message. What I have is there are posts that multiple users can view, but it needs to separate by user who has actually viewed it. So if User A viewed Post 1, it would no longer show that Post 1 is a new item to view, but to User B, it would still show that Post 1 is a new item to view. I've search for other ideas

YYYY-MM column type in PostgreSQL

谁都会走 提交于 2020-11-29 08:20:36
问题 I need to a value associated to a month and a user in a table. And I want to perform queries on it. I don't know if there is a column data type for this type of need. If not, should I: Create a string field and build year-month concatenation (2017-01) Create a int field and build year-month concatenation (201701) Create two columns (one year and one month) Create a date column at the beginning of the month (2017-01-01 00:00:00) Something else? The objective is to run queries like (pseudo-SQL)

YYYY-MM column type in PostgreSQL

心不动则不痛 提交于 2020-11-29 08:20:01
问题 I need to a value associated to a month and a user in a table. And I want to perform queries on it. I don't know if there is a column data type for this type of need. If not, should I: Create a string field and build year-month concatenation (2017-01) Create a int field and build year-month concatenation (201701) Create two columns (one year and one month) Create a date column at the beginning of the month (2017-01-01 00:00:00) Something else? The objective is to run queries like (pseudo-SQL)

YYYY-MM column type in PostgreSQL

余生长醉 提交于 2020-11-29 08:19:56
问题 I need to a value associated to a month and a user in a table. And I want to perform queries on it. I don't know if there is a column data type for this type of need. If not, should I: Create a string field and build year-month concatenation (2017-01) Create a int field and build year-month concatenation (201701) Create two columns (one year and one month) Create a date column at the beginning of the month (2017-01-01 00:00:00) Something else? The objective is to run queries like (pseudo-SQL)