J.Zil
J.Zil

Reputation: 2449

When to put payments in their own SQL table?

I have a system where users posts data and they can upgrade their post by optionioally paying to upgrade. This is the information I want to store from stripe on their payment response:

CREATE TABLE IF NOT EXISTS `db`.`pay` (
  `payments_id` int(11) NOT NULL AUTO_INCREMENT
   payment, unique index',
  `stripe_id`
  `card_id`
  `brand`
  `amount`
  `created`
  `currency`
  `paid`
  `refunded`
  `exp_month`
  `exp_year`
  `last4`
  `country`
  `fingerprint`
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='payments';

Should this be in the same table as the one containing the main post data, or should it be a separate and linked table. What logic is used to make this decision?

On one hand it seems nice to separate it but then you also have the overhead of linking the tables. Only one payment will ever be associated with one post.

Upvotes: 3

Views: 225

Answers (1)

Tim
Tim

Reputation: 783

Card data should be in a different table with a userId that links to your user table.

With limited knowledge of what you're trying to achieve I would say you need at least 3 tables.

  1. User Table
  2. Post Table with userId linking back to user table
  3. Payment Card Table with userId linking back to user table

Upvotes: 2

Related Questions