-- phpMyAdmin SQL Dump
-- version 5.2.2
-- https://www.phpmyadmin.net/
--
-- Host: danceiasql.mysql.db
-- Generation Time: Dec 17, 2025 at 04:42 PM
-- Wersja serwera: 8.4.6-6
-- Wersja PHP: 8.1.33

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Baza danych: `danceiasql`
--

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `zx_companies`
--

CREATE TABLE `zx_companies` (
  `company_id` int UNSIGNED NOT NULL,
  `company_name` varchar(255) NOT NULL,
  `company_nip` varchar(20) DEFAULT NULL,
  `company_address` varchar(255) DEFAULT NULL,
  `company_postal_code` varchar(10) DEFAULT NULL,
  `company_city` varchar(255) DEFAULT NULL,
  `company_country` varchar(2) DEFAULT 'PL',
  `company_owner_user_id` int UNSIGNED DEFAULT NULL,
  `company_is_active` tinyint(1) NOT NULL DEFAULT '1',
  `company_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `company_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `zx_licenses`
--

CREATE TABLE `zx_licenses` (
  `license_id` int UNSIGNED NOT NULL,
  `license_company_id` int UNSIGNED NOT NULL,
  `license_valid_from` date NOT NULL,
  `license_valid_to` date NOT NULL,
  `license_price` decimal(10,2) NOT NULL,
  `license_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `zx_password_resets`
--

CREATE TABLE `zx_password_resets` (
  `reset_id` int UNSIGNED NOT NULL,
  `reset_user_id` int UNSIGNED NOT NULL,
  `reset_selector` varchar(255) NOT NULL,
  `reset_token_hash` varchar(255) NOT NULL,
  `reset_expires_at` datetime NOT NULL,
  `reset_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `zx_playlists`
--

CREATE TABLE `zx_playlists` (
  `playlist_id` int UNSIGNED NOT NULL,
  `playlist_user_id` int UNSIGNED NOT NULL,
  `playlist_name` varchar(100) NOT NULL,
  `playlist_is_public` tinyint(1) DEFAULT '0',
  `playlist_created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `zx_playlist_tracks`
--

CREATE TABLE `zx_playlist_tracks` (
  `playlist_track_id` int UNSIGNED NOT NULL,
  `playlist_track_playlist_id` int UNSIGNED NOT NULL,
  `playlist_track_track_id` int UNSIGNED NOT NULL,
  `playlist_track_position` int UNSIGNED NOT NULL,
  `playlist_track_added_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `zx_tracks`
--

CREATE TABLE `zx_tracks` (
  `track_id` int UNSIGNED NOT NULL,
  `track_created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `track_filename` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `track_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `track_artist` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `track_style` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL,
  `track_bpm` tinyint UNSIGNED DEFAULT NULL,
  `track_play_count` int UNSIGNED DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `zx_users`
--

CREATE TABLE `zx_users` (
  `user_id` int UNSIGNED NOT NULL,
  `user_email` varchar(255) NOT NULL,
  `user_phone` varchar(32) DEFAULT NULL,
  `user_password_hash` varchar(255) NOT NULL,
  `user_is_active` tinyint(1) NOT NULL DEFAULT '1',
  `user_created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `user_updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------

--
-- Struktura tabeli dla tabeli `zx_user_company`
--

CREATE TABLE `zx_user_company` (
  `user_id` int UNSIGNED NOT NULL,
  `company_id` int UNSIGNED NOT NULL,
  `role` enum('ADMIN','MANAGER','USER') CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT 'USER',
  `joined_at` datetime DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Indeksy dla zrzutów tabel
--

--
-- Indeksy dla tabeli `zx_companies`
--
ALTER TABLE `zx_companies`
  ADD PRIMARY KEY (`company_id`),
  ADD UNIQUE KEY `uk_company_nip` (`company_nip`),
  ADD KEY `fk_company_owner` (`company_owner_user_id`);

--
-- Indeksy dla tabeli `zx_licenses`
--
ALTER TABLE `zx_licenses`
  ADD PRIMARY KEY (`license_id`),
  ADD KEY `k_license_company` (`license_company_id`);

--
-- Indeksy dla tabeli `zx_password_resets`
--
ALTER TABLE `zx_password_resets`
  ADD PRIMARY KEY (`reset_id`),
  ADD KEY `fk_password_reset_user` (`reset_user_id`);

--
-- Indeksy dla tabeli `zx_playlists`
--
ALTER TABLE `zx_playlists`
  ADD PRIMARY KEY (`playlist_id`),
  ADD KEY `fk_playlist_user` (`playlist_user_id`);

--
-- Indeksy dla tabeli `zx_playlist_tracks`
--
ALTER TABLE `zx_playlist_tracks`
  ADD PRIMARY KEY (`playlist_track_id`),
  ADD UNIQUE KEY `uq_playlist_position` (`playlist_track_playlist_id`,`playlist_track_position`),
  ADD KEY `fk_pt_track` (`playlist_track_track_id`);

--
-- Indeksy dla tabeli `zx_tracks`
--
ALTER TABLE `zx_tracks`
  ADD PRIMARY KEY (`track_id`),
  ADD KEY `idx_track_title` (`track_title`),
  ADD KEY `idx_track_style` (`track_style`),
  ADD KEY `idx_track_bpm` (`track_bpm`),
  ADD KEY `idx_track_created` (`track_created_at`);

--
-- Indeksy dla tabeli `zx_users`
--
ALTER TABLE `zx_users`
  ADD PRIMARY KEY (`user_id`),
  ADD UNIQUE KEY `uk_user_email` (`user_email`);

--
-- Indeksy dla tabeli `zx_user_company`
--
ALTER TABLE `zx_user_company`
  ADD PRIMARY KEY (`user_id`,`company_id`),
  ADD KEY `fk_uc_company` (`company_id`);

--
-- AUTO_INCREMENT dla zrzuconych tabel
--

--
-- AUTO_INCREMENT dla tabeli `zx_companies`
--
ALTER TABLE `zx_companies`
  MODIFY `company_id` int UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT dla tabeli `zx_licenses`
--
ALTER TABLE `zx_licenses`
  MODIFY `license_id` int UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT dla tabeli `zx_password_resets`
--
ALTER TABLE `zx_password_resets`
  MODIFY `reset_id` int UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT dla tabeli `zx_playlists`
--
ALTER TABLE `zx_playlists`
  MODIFY `playlist_id` int UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT dla tabeli `zx_playlist_tracks`
--
ALTER TABLE `zx_playlist_tracks`
  MODIFY `playlist_track_id` int UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT dla tabeli `zx_tracks`
--
ALTER TABLE `zx_tracks`
  MODIFY `track_id` int UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT dla tabeli `zx_users`
--
ALTER TABLE `zx_users`
  MODIFY `user_id` int UNSIGNED NOT NULL AUTO_INCREMENT;

--
-- Ograniczenia dla zrzutów tabel
--

--
-- Ograniczenia dla tabeli `zx_companies`
--
ALTER TABLE `zx_companies`
  ADD CONSTRAINT `fk_company_owner` FOREIGN KEY (`company_owner_user_id`) REFERENCES `zx_users` (`user_id`) ON DELETE SET NULL;

--
-- Ograniczenia dla tabeli `zx_licenses`
--
ALTER TABLE `zx_licenses`
  ADD CONSTRAINT `fk_license_company` FOREIGN KEY (`license_company_id`) REFERENCES `zx_companies` (`company_id`) ON DELETE CASCADE ON UPDATE CASCADE;

--
-- Ograniczenia dla tabeli `zx_password_resets`
--
ALTER TABLE `zx_password_resets`
  ADD CONSTRAINT `fk_password_reset_user` FOREIGN KEY (`reset_user_id`) REFERENCES `zx_users` (`user_id`) ON DELETE CASCADE;

--
-- Ograniczenia dla tabeli `zx_playlists`
--
ALTER TABLE `zx_playlists`
  ADD CONSTRAINT `fk_playlist_user` FOREIGN KEY (`playlist_user_id`) REFERENCES `zx_users` (`user_id`) ON DELETE CASCADE;

--
-- Ograniczenia dla tabeli `zx_playlist_tracks`
--
ALTER TABLE `zx_playlist_tracks`
  ADD CONSTRAINT `fk_pt_playlist` FOREIGN KEY (`playlist_track_playlist_id`) REFERENCES `zx_playlists` (`playlist_id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_pt_track` FOREIGN KEY (`playlist_track_track_id`) REFERENCES `zx_tracks` (`track_id`) ON DELETE CASCADE;

--
-- Ograniczenia dla tabeli `zx_user_company`
--
ALTER TABLE `zx_user_company`
  ADD CONSTRAINT `fk_uc_company` FOREIGN KEY (`company_id`) REFERENCES `zx_companies` (`company_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  ADD CONSTRAINT `fk_uc_user` FOREIGN KEY (`user_id`) REFERENCES `zx_users` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
