SQL
SQL
-- TWITTER
CREATE TABLE IF NOT EXISTS `phone_twitter_hashtags` (
`hashtag` VARCHAR(50) NOT NULL,
`amount` INT NOT NULL DEFAULT 0,
`last_used` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE
CURRENT_TIMESTAMP,
`content` VARCHAR(280),
`attachments` TEXT, -- json array of attachments
`reply_to` VARCHAR(50) DEFAULT NULL, -- the tweet / reply this tweet / reply
was a reply to
`sender` VARCHAR(20) NOT NULL, -- the person who sent the message, matches to
`username` in phone_twitter_accounts
`recipient` VARCHAR(20) NOT NULL, -- the person who received the message,
matches to `username` in phone_twitter_accounts
`content` VARCHAR(1000),
`attachments` TEXT, -- json array of attachments
-- PHONE
CREATE TABLE IF NOT EXISTS `phone_phone_contacts` (
`contact_phone_number` VARCHAR(15) NOT NULL, -- the phone number of the contact
`firstname` VARCHAR(50) NOT NULL DEFAULT "",
`lastname` VARCHAR(50) NOT NULL DEFAULT "",
`profile_image` VARCHAR(500) DEFAULT NULL,
`email` VARCHAR(50) DEFAULT NULL,
`address` VARCHAR(50) DEFAULT NULL,
`favourite` BOOLEAN DEFAULT FALSE,
`phone_number` VARCHAR(15) NOT NULL, -- the phone number of the person who
added the contact
-- INSTAGRAM
CREATE TABLE IF NOT EXISTS `phone_instagram_accounts` (
`display_name` VARCHAR(30) NOT NULL,
`sender` VARCHAR(20) NOT NULL, -- the person who sent the message, matches to
`username` in phone_instagram_accounts
`recipient` VARCHAR(20) NOT NULL, -- the person who received the message,
matches to `username` in phone_instagram_accounts
`content` VARCHAR(1000),
`attachments` TEXT, -- json array of attachments
-- CLOCK
CREATE TABLE IF NOT EXISTS `phone_clock_alarms` (
`id` VARCHAR(10) NOT NULL,
`phone_number` VARCHAR(15) NOT NULL,
-- TINDER
CREATE TABLE IF NOT EXISTS `phone_tinder_accounts` (
`name` VARCHAR(50) NOT NULL,
`phone_number` VARCHAR(15) NOT NULL,
`photos` TEXT, -- json array of photos
`bio` VARCHAR(500) DEFAULT NULL,
`dob` DATE NOT NULL,
`liked` BOOLEAN NOT NULL DEFAULT FALSE, -- whether the swiper liked the swipee
or not
`sender` VARCHAR(15) NOT NULL, -- the phone number of the person who sent the
message
`recipient` VARCHAR(15) NOT NULL, -- the phone number of the person who
received the message
`content` VARCHAR(1000),
`attachments` TEXT, -- json array of attachments
-- MESSAGES
CREATE TABLE IF NOT EXISTS `phone_message_channels` (
`id` INT NOT NULL AUTO_INCREMENT,
-- DARKCHAT
CREATE TABLE IF NOT EXISTS `phone_darkchat_accounts` (
`phone_number` VARCHAR(15) NOT NULL,
`username` VARCHAR(20) NOT NULL,
-- WALLET
CREATE TABLE IF NOT EXISTS `phone_wallet_transactions` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`phone_number` VARCHAR(15) NOT NULL,
-- YELLOW PAGES
CREATE TABLE IF NOT EXISTS `phone_yellow_pages_posts` (
`id` VARCHAR(10) NOT NULL,
`phone_number` VARCHAR(15) NOT NULL,
`title` VARCHAR(50) NOT NULL,
`description` VARCHAR(1000) NOT NULL,
-- BACKUPS
CREATE TABLE IF NOT EXISTS `phone_backups` (
`id` VARCHAR(100) NOT NULL,
`phone_number` VARCHAR(15) NOT NULL,
-- MARKETPLACE
CREATE TABLE IF NOT EXISTS `phone_marketplace_posts` (
`id` VARCHAR(10) NOT NULL,
`phone_number` VARCHAR(15) NOT NULL,
-- MUSIC
CREATE TABLE IF NOT EXISTS `phone_music_playlists` (
`id` VARCHAR(10) NOT NULL,
`phone_number` VARCHAR(15) NOT NULL,
-- MAIL
CREATE TABLE IF NOT EXISTS `phone_mail_accounts` (
`address` VARCHAR(100) NOT NULL,
`password` VARCHAR(100) NOT NULL,
PRIMARY KEY (`address`)
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
-- COMPANIES APP
CREATE TABLE IF NOT EXISTS `phone_services_channels` (
`id` VARCHAR(10) NOT NULL,
`phone_number` VARCHAR(15) NOT NULL,
`company` VARCHAR(50) NOT NULL,
-- MAPS
CREATE TABLE IF NOT EXISTS `phone_maps_locations` (
`id` VARCHAR(10) NOT NULL,
`phone_number` VARCHAR(15) NOT NULL,
-- CRYPTO
CREATE TABLE IF NOT EXISTS `phone_crypto` (
`id` VARCHAR(100) NOT NULL, -- player identifier
`coin` VARCHAR(15) NOT NULL, -- coin, for example "bitcoin"
`amount` DOUBLE NOT NULL DEFAULT 0, -- amount of coins
`invested` INT(11) NOT NULL DEFAULT 0, -- amount of $$$ invested
-- ACCOUNT SWITCHER
CREATE TABLE IF NOT EXISTS `phone_logged_in_accounts` (
`phone_number` VARCHAR(15) NOT NULL,
`app` VARCHAR(50) NOT NULL,
`username` VARCHAR(100) NOT NULL,
-- TIKTOK
CREATE TABLE IF NOT EXISTS `phone_tiktok_accounts` (
`name` VARCHAR(30) NOT NULL,
`bio` VARCHAR(100) DEFAULT NULL,
`avatar` VARCHAR(500) DEFAULT NULL,
-- VOICE MEMOS
CREATE TABLE IF NOT EXISTS `phone_voice_memos_recordings` (
`id` VARCHAR(10) NOT NULL,
`phone_number` VARCHAR(15) NOT NULL,
DELIMITER //
-- Instagram triggers
-- Incrémentation du post_count après l'ajout d'un post
CREATE TRIGGER IF NOT EXISTS phone_instagram_increment_post_count
AFTER INSERT ON phone_instagram_posts
FOR EACH ROW
WHEN NEW.username IS NOT NULL
BEGIN
UPDATE phone_instagram_accounts
SET post_count = post_count + 1
WHERE username = NEW.username;
END;
UPDATE phone_instagram_accounts
SET following_count = following_count + 1
WHERE username = NEW.follower;
END;
CREATE TRIGGER IF NOT EXISTS phone_instagram_update_counts_after_unfollow
AFTER DELETE ON phone_instagram_follows
FOR EACH ROW
BEGIN
UPDATE phone_instagram_accounts
SET follower_count = CASE WHEN follower_count > 0 THEN follower_count - 1 ELSE
0 END
WHERE username = OLD.followed;
UPDATE phone_instagram_accounts
SET following_count = CASE WHEN following_count > 0 THEN following_count - 1
ELSE 0 END
WHERE username = OLD.follower;
END;
//
DELIMITER ;