26 lines
953 B
SQL
26 lines
953 B
SQL
-- Create suppliers table with the same structure as customers minus loyalty fields
|
|
CREATE TABLE IF NOT EXISTS suppliers (
|
|
id int(11) NOT NULL AUTO_INCREMENT,
|
|
name varchar(255) NOT NULL,
|
|
email varchar(255) DEFAULT NULL,
|
|
phone varchar(50) DEFAULT NULL,
|
|
tax_id varchar(50) DEFAULT NULL,
|
|
balance decimal(15,3) DEFAULT NULL,
|
|
credit_limit decimal(15,3) DEFAULT NULL,
|
|
created_at timestamp NULL DEFAULT CURRENT_TIMESTAMP,
|
|
total_spent decimal(15,3) DEFAULT NULL,
|
|
PRIMARY KEY (id)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
|
|
|
-- Migrate data
|
|
INSERT INTO suppliers (id, name, email, phone, tax_id, balance, credit_limit, created_at, total_spent)
|
|
SELECT id, name, email, phone, tax_id, balance, credit_limit, created_at, total_spent
|
|
FROM customers
|
|
WHERE type = 'supplier';
|
|
|
|
-- Clean up customers table
|
|
DELETE FROM customers WHERE type = 'supplier';
|
|
|
|
-- Remove type column from customers
|
|
ALTER TABLE customers DROP COLUMN type;
|