database-design

How to handle expired items?

My site allows users to post things on the site with an expiry date. Once the item has expired, it will no longer be displayed in the listings. Posts can also be closed, canceled, or completed. I think it would be be nicest just to be able to check for one attribute or status ("is active") rather than having to check for [is not expired,...

Drawbacks of using an integer as a bitfield?

I have a bunch of boolean options for things like "acceptable payment types" which can include things like cash, credit card, cheque, paypal, etc. Rather than having a half dozen booleans in my DB, I can just use an integer and assign each payment method an integer, like so PAYMENT_METHODS = ( (1<<0, 'Cash'), (1<<1, 'Credit Card...

Saving an IP adddress to DB

I want to save a user's IP address to my database just in case any legal issues come up and we need to track down who performed what action. Since I highly doubt I will ever actually need to use this data (well, maybe for counting unique hits or something) do you think I can just dump the REMOTE_ADDR into a field? If so, what should the ...

Buddy List: Relational Database Table Design

So, the modern concept of the buddy list: Let's say we have a table called Person. Now, that Person needs to have many buddies (of which each buddy is also in the person class). The most obvious way to construct a relationship would be through a join table. i.e. buddyID person1_id person2_id 0 1 2 1 3 ...

Database date fields - Naming Convention

What's a good way of naming date/datetime fields? Can't decide if I want to use things like expiry_date, end_time, created_on, or simply expires, modified. ...

Storing year/make/model in a database?

Here's what I'm thinking (excuse the Django format): class VehicleMake(Model): name = CharField(max_length=50) class VehicleModel(Model): make = ForeignKey(VehicleMake) name = CharField(max_length=50) class VehicleYear(Model): model = ForeignKey(VehicleModel) # or ManyToManyField year = PositiveIntegerField() Thi...

Strategy to structure a search index in a relational database

I am interested in suggestions for building an efficient and robust structure for indexing products in a new database I am building (i'm using MySql) When a product is entered through the form there are three parts I am interested in indexing for searching purposes. The product title The product description Tags The most important ...

The best way to structure this database?

At the moment I'm doing this: gems(id, name, colour, level, effects, source) id is the primary key and is not auto-increment. A typical row of data would look like this: id => 40153 name => Veiled Ametrine colour => Orange level => 80 effects => +12 sp, +10 hit source => Ametrine (Some of you gamers might s...

How to represent a Many-To-Many relationship in XML or other simple file format?

I have a list management appliaction that stores its data in a many-to-many relationship database. I.E. A note can be in any number of lists, and a list can have any number of notes. I also can export this data to and XML file and import it in another instance of my app for sharing lists between users. However, this is based on a lega...

Two Tables Serving as one Model in Rails

Is is possible in rails to setup on model which is dependant on a join from two tables? This would mean that for the the model record to be found/updated/destroyed there would need to be both records in both database tables linked together in a join. The model would just be all the columns of both tables wrapped together which may then b...

MySql "comments" parameter as descriptor?

So, I'm trying to learn a lot at once, and this place is really helpful! I'm making a little running log website for myself and maybe a few other people, and I have it so that the user can add workouts for each day. With each workout, I have a variety of information the user can fill out for the workout, such as running distance, time,...

Best XML Based Database

I had been assigned to develop a system on where we would get a XML from multiple sources (millions of xml) and put them in some database like and judging from the xml i would receive, there wont be any concrete structure even if they are from the same source. With this reason i think i cannot suggest RDMS and currently looking at NoSQL ...

How would I associate a "Note" class to 4+ classes without creating lookup table for each association.

I'm creating a project tasklist application. I have project, section, task, issue classes, and would like to use one class to be able to add simple notes to any object instance of those classes. The task, issue tables both use a standard identity field as a primary key. The section table has a two field primary key. The project table ...

Need recommendation for a table structure

I have an entity which has 4 different types of property that could have only one value for each case which are boolean, decimal, string or text. I don't want to define the table with 4 boolean, decimal, nvarchar and ntext columns. What would you recommend to cover this case? Update: I'm using MS SQL Server. Here is the class definit...

How to store a list in a column of a database table.

Howdy! So, per Mehrdad's answer to a related question, I get it that a "proper" database table column doesn't store a list. Rather, you should create another table that effectively holds the elements of said list and then link to it directly or through a junction table. However, the type of list I want to create will be composed of un...

Database Design - How do I setup an FK relationship to 1 of 2 tables??

What is the best way to maintain a unique ID field across multiple database tables? My database contains both businesses and people, and both entities need to have a unique ID field associated with it. In addition, there are other tables (for example Addresses) which can reference either a business or a person using their ID as a foreig...

Creating tables in pgadmin sql editor ?

I am failing in creating tables via the PGadmin III SQL editor - even if the syntax is generated by the frontend: CREATE TABLE testtable ( id integer, "name" character varying(100) ) WITH ( OIDS = FALSE ) ; Error message is in german, but basically says that there's supposed to be a syntax error.. FEHLER: Syntaxfehler bei ...

Why should i use 1 table instead of two?

I have two tables called (Up|Down)Vote, you can do BOTH upvote and downvote thus it isnt one table with a bool. People suggested i should use one table called votes and have a field called type. Why should i do this? I think writing the unique table name is easier then writing Vote then the extra where statement (type & upOrDownTypeBit)...

RoR DB Design - Do I need to use a :through table?

I'm designing a basic sports application in RoR and I don't know if my database design is correct. For instance, I have: class Game < ActiveRecord::Base has_one :home_team has_one :away_team end class Team < ActiveRecord::Base has_many :games end However, someone told me the better way to do this is: class Game < ActiveRecord:...

CSV to DataMapper Import

This is probably very simple, but I'm quite new to ruby and active record. I've got a CSV dump of a database which I'm trying to import to a database using DataMapper. I'm having trouble understanding which type of relationships I should define in the models so that it matches what is defined CSV. Here's what data I've got from the CS...