-- phpMyAdmin SQL Dump
-- version 5.2.1deb3
-- https://www.phpmyadmin.net/
--
-- Anamakine: localhost:3306
-- Üretim Zamanı: 28 Şub 2026, 13:43:25
-- Sunucu sürümü: 8.0.45-0ubuntu0.24.04.1
-- PHP Sürümü: 8.3.6

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 */;

--
-- Veritabanı: `goldr`
--

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

--
-- Tablo için tablo yapısı `agenda_notes`
--

CREATE TABLE `agenda_notes` (
  `profile_id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `note_key` varchar(100) COLLATE utf8mb4_general_ci NOT NULL,
  `note_value` longtext COLLATE utf8mb4_general_ci
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `app_settings`
--

CREATE TABLE `app_settings` (
  `profile_id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `setting_key` varchar(100) COLLATE utf8mb4_general_ci NOT NULL,
  `setting_value` longtext COLLATE utf8mb4_general_ci,
  `setting_type` varchar(20) COLLATE utf8mb4_general_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `audit_logs`
--

CREATE TABLE `audit_logs` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `user_name` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `action` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `target_table` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `target_id` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `details` text COLLATE utf8mb4_general_ci,
  `ip_address` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `barcode_history`
--

CREATE TABLE `barcode_history` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `barcode` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `product_type` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `gram` decimal(19,4) DEFAULT '0.0000',
  `karat` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `buy_date` datetime DEFAULT NULL,
  `buy_from` varchar(150) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `buy_price` decimal(19,4) DEFAULT '0.0000',
  `buy_method` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `is_sold` tinyint(1) DEFAULT '0',
  `sell_date` datetime DEFAULT NULL,
  `sell_to` varchar(150) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `sell_price` decimal(19,4) DEFAULT '0.0000',
  `sell_method` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `movements_json` longtext COLLATE utf8mb4_general_ci,
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `categories`
--

CREATE TABLE `categories` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `name` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `customer_history_events`
--

CREATE TABLE `customer_history_events` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `person_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `person_full_name` varchar(150) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `event_date` datetime DEFAULT NULL,
  `event_type` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `description` text COLLATE utf8mb4_general_ci,
  `debt_original` decimal(19,4) DEFAULT '0.0000',
  `credit_original` decimal(19,4) DEFAULT '0.0000',
  `currency` varchar(20) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `transaction_amount` decimal(19,4) DEFAULT '0.0000',
  `related_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `debt_records`
--

CREATE TABLE `debt_records` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `person_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `person_full_name` varchar(150) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `record_type` varchar(20) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `transaction_date` date DEFAULT NULL,
  `debt_category` varchar(20) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `original_amount` decimal(19,4) DEFAULT '0.0000',
  `currency` varchar(10) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `total_amount_base` decimal(19,4) DEFAULT '0.0000',
  `product_name` varchar(150) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `product_quantity` decimal(19,4) DEFAULT '0.0000',
  `description` text COLLATE utf8mb4_general_ci,
  `status` varchar(20) COLLATE utf8mb4_general_ci DEFAULT 'Active',
  `due_date` date DEFAULT NULL,
  `is_paid` tinyint(1) DEFAULT '0',
  `paid_amount_base` decimal(19,4) DEFAULT '0.0000',
  `paid_quantity` decimal(19,4) DEFAULT '0.0000',
  `payment_date` date DEFAULT NULL,
  `is_deleted` tinyint(1) DEFAULT '0',
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `depots`
--

CREATE TABLE `depots` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `name` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `is_deleted` tinyint(1) DEFAULT '0',
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `document_counters`
--

CREATE TABLE `document_counters` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `doc_type` varchar(20) COLLATE utf8mb4_general_ci NOT NULL,
  `last_no` int NOT NULL DEFAULT '0',
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `financial_accounts`
--

CREATE TABLE `financial_accounts` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `name` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `type` varchar(20) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `is_deleted` tinyint(1) DEFAULT '0',
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `financial_transactions`
--

CREATE TABLE `financial_transactions` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `account_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `transaction_date` date DEFAULT NULL,
  `transaction_type` varchar(20) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `amount` decimal(19,4) DEFAULT '0.0000',
  `currency` varchar(10) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `base_amount` decimal(19,4) DEFAULT '0.0000',
  `description` text COLLATE utf8mb4_general_ci,
  `related_person_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `related_record_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `is_deleted` tinyint(1) DEFAULT '0',
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `persons`
--

CREATE TABLE `persons` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `full_name` varchar(150) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `phone_number` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `address` text COLLATE utf8mb4_general_ci,
  `notes` text COLLATE utf8mb4_general_ci,
  `is_deleted` tinyint(1) DEFAULT '0',
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `product_definitions`
--

CREATE TABLE `product_definitions` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `stock_type` varchar(20) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `name` varchar(150) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `category_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `barcode_header` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `karat_purity` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `workmanship_fee` decimal(19,4) DEFAULT '0.0000',
  `workmanship_currency` varchar(10) COLLATE utf8mb4_general_ci DEFAULT 'TRY',
  `default_purchase_price` decimal(19,4) DEFAULT '0.0000',
  `default_sale_price` decimal(19,4) DEFAULT '0.0000',
  `purchase_currency` varchar(10) COLLATE utf8mb4_general_ci DEFAULT 'TRY',
  `sale_currency` varchar(10) COLLATE utf8mb4_general_ci DEFAULT 'TRY',
  `default_weight_gr` decimal(19,4) DEFAULT '0.0000',
  `is_active` tinyint(1) DEFAULT '1',
  `is_deleted` tinyint(1) DEFAULT '0',
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `profiles`
--

CREATE TABLE `profiles` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `name` varchar(100) COLLATE utf8mb4_general_ci NOT NULL,
  `is_active` tinyint(1) DEFAULT '1',
  `is_deleted` tinyint(1) DEFAULT '0',
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `deleted_profiles`
--

CREATE TABLE `deleted_profiles` (
  `profile_id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_name` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `transaction_uuid` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `device_id` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `deleted_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `repair_records`
--

CREATE TABLE `repair_records` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `customer_full_name` varchar(150) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `product_description` text COLLATE utf8mb4_general_ci,
  `complaint_request` text COLLATE utf8mb4_general_ci,
  `receipt_date` date DEFAULT NULL,
  `estimated_fee` decimal(19,4) DEFAULT '0.0000',
  `fee_currency` varchar(10) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `status` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `delivery_date` date DEFAULT NULL,
  `notes` text COLLATE utf8mb4_general_ci,
  `is_deleted` tinyint(1) DEFAULT '0',
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `sales`
--

CREATE TABLE `sales` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `sale_date` date DEFAULT NULL,
  `customer_full_name` varchar(150) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `total_amount` decimal(19,4) DEFAULT '0.0000',
  `currency` varchar(10) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `payment_method_summary` text COLLATE utf8mb4_general_ci,
  `products_json` longtext COLLATE utf8mb4_general_ci,
  `is_deleted` tinyint(1) DEFAULT '0',
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `scheduled_transactions`
--

CREATE TABLE `scheduled_transactions` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `due_date` date DEFAULT NULL,
  `transaction_type` varchar(20) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `amount` decimal(19,4) DEFAULT '0.0000',
  `currency` varchar(10) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `description` text COLLATE utf8mb4_general_ci,
  `target` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `person_full_name` varchar(150) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `status` varchar(20) COLLATE utf8mb4_general_ci DEFAULT 'Pending',
  `is_deleted` tinyint(1) DEFAULT '0',
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `service_definitions`
--

CREATE TABLE `service_definitions` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `name` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `custom_columns_json` longtext COLLATE utf8mb4_general_ci
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `service_jobs`
--

CREATE TABLE `service_jobs` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `service_def_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `customer_name` varchar(150) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `description` text COLLATE utf8mb4_general_ci,
  `status` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `fee` decimal(19,4) DEFAULT '0.0000',
  `currency` varchar(10) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `start_date` date DEFAULT NULL,
  `delivery_date` date DEFAULT NULL,
  `dynamic_data_json` longtext COLLATE utf8mb4_general_ci
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `stock_items`
--

CREATE TABLE `stock_items` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `depot_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `stock_type` varchar(20) COLLATE utf8mb4_general_ci DEFAULT 'Product',
  `item_type_name` varchar(150) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `quantity` decimal(19,4) DEFAULT '0.0000',
  `quantity_gr` decimal(19,4) DEFAULT '0.0000',
  `purchase_price_base` decimal(19,4) DEFAULT '0.0000',
  `unique_barcode` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `is_deleted` tinyint(1) DEFAULT '0',
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `stock_movements`
--

CREATE TABLE `stock_movements` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `date` datetime DEFAULT NULL,
  `item_type` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `product_name` varchar(150) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `operation_type` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `quantity` decimal(19,4) DEFAULT NULL,
  `source` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `destination` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `description` text COLLATE utf8mb4_general_ci,
  `user` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `taxes`
--

CREATE TABLE `taxes` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `name` varchar(120) COLLATE utf8mb4_general_ci NOT NULL,
  `rate` decimal(19,4) NOT NULL DEFAULT '0.0000',
  `type` varchar(10) COLLATE utf8mb4_general_ci NOT NULL,
  `country` varchar(2) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `active` tinyint(1) DEFAULT '1',
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `tax_applications`
--

CREATE TABLE `tax_applications` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `source_table` varchar(60) COLLATE utf8mb4_general_ci NOT NULL,
  `source_id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `subtotal` decimal(19,4) NOT NULL DEFAULT '0.0000',
  `tax_total` decimal(19,4) NOT NULL DEFAULT '0.0000',
  `grand_total` decimal(19,4) NOT NULL DEFAULT '0.0000',
  `currency` varchar(10) COLLATE utf8mb4_general_ci NOT NULL,
  `snapshot_json` longtext COLLATE utf8mb4_general_ci,
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `tax_profiles`
--

CREATE TABLE `tax_profiles` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `name` varchar(120) COLLATE utf8mb4_general_ci NOT NULL,
  `description` text COLLATE utf8mb4_general_ci,
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `tax_profile_items`
--

CREATE TABLE `tax_profile_items` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `tax_profile_id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `tax_id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `priority` int NOT NULL DEFAULT '0',
  `enabled_by_default` tinyint(1) DEFAULT '1',
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `users`
--

CREATE TABLE `users` (
  `id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `username` varchar(50) COLLATE utf8mb4_general_ci NOT NULL,
  `full_name` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `password_hash` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `role` varchar(20) COLLATE utf8mb4_general_ci DEFAULT 'employee',
  `is_active` tinyint(1) DEFAULT '1',
  `is_deleted` tinyint(1) DEFAULT '0',
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `user_access_scopes`
--

CREATE TABLE `user_access_scopes` (
  `user_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `scope_type` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `target_id` varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `user_permissions`
--

CREATE TABLE `user_permissions` (
  `user_id` char(36) COLLATE utf8mb4_general_ci NOT NULL,
  `permission_code` varchar(50) COLLATE utf8mb4_general_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

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

--
-- Tablo için tablo yapısı `global_sync_events`
--

CREATE TABLE `global_sync_events` (
  `id` bigint NOT NULL,
  `transaction_uuid` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `device_id` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `profile_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `table_name` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `action_type` varchar(20) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `record_id` char(36) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `payload_json` json DEFAULT NULL,
  `created_at` datetime DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Dökümü yapılmış tablolar için indeksler
--

--
-- Tablo için indeksler `agenda_notes`
--
ALTER TABLE `agenda_notes`
  ADD PRIMARY KEY (`profile_id`,`note_key`),
  ADD KEY `idx_profile` (`profile_id`);

--
-- Tablo için indeksler `app_settings`
--
ALTER TABLE `app_settings`
  ADD PRIMARY KEY (`profile_id`,`setting_key`);

--
-- Tablo için indeksler `audit_logs`
--
ALTER TABLE `audit_logs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_audit_profiles` (`profile_id`);

--
-- Tablo için indeksler `barcode_history`
--
ALTER TABLE `barcode_history`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_barcode_profiles` (`profile_id`);

--
-- Tablo için indeksler `categories`
--
ALTER TABLE `categories`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_cats_profiles` (`profile_id`);

--
-- Tablo için indeksler `customer_history_events`
--
ALTER TABLE `customer_history_events`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_hist_profiles` (`profile_id`);

--
-- Tablo için indeksler `debt_records`
--
ALTER TABLE `debt_records`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_debt_profiles` (`profile_id`);

--
-- Tablo için indeksler `depots`
--
ALTER TABLE `depots`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_depots_profiles` (`profile_id`);

--
-- Tablo için indeksler `document_counters`
--
ALTER TABLE `document_counters`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_doc_counter` (`profile_id`,`doc_type`);

--
-- Tablo için indeksler `financial_accounts`
--
ALTER TABLE `financial_accounts`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_accounts_profiles` (`profile_id`);

--
-- Tablo için indeksler `financial_transactions`
--
ALTER TABLE `financial_transactions`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_trans_profiles` (`profile_id`),
  ADD KEY `fk_trans_accounts` (`account_id`);

--
-- Tablo için indeksler `global_sync_events`
--
ALTER TABLE `global_sync_events`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_profile_created` (`profile_id`,`created_at`),
  ADD KEY `idx_tx_uuid` (`transaction_uuid`);

--
-- Tablo için indeksler `persons`
--
ALTER TABLE `persons`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_persons_profiles` (`profile_id`);

--
-- Tablo için indeksler `product_definitions`
--
ALTER TABLE `product_definitions`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_products_profiles` (`profile_id`);

--
-- Tablo için indeksler `profiles`
--
ALTER TABLE `profiles`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `name` (`name`);

--
-- Tablo için indeksler `deleted_profiles`
--
ALTER TABLE `deleted_profiles`
  ADD PRIMARY KEY (`profile_id`),
  ADD KEY `idx_deleted_profiles_deleted_at` (`deleted_at`);

--
-- Tablo için indeksler `repair_records`
--
ALTER TABLE `repair_records`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_repair_profiles` (`profile_id`);

--
-- Tablo için indeksler `sales`
--
ALTER TABLE `sales`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_sales_profiles` (`profile_id`);

--
-- Tablo için indeksler `scheduled_transactions`
--
ALTER TABLE `scheduled_transactions`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_st_profiles` (`profile_id`);

--
-- Tablo için indeksler `service_definitions`
--
ALTER TABLE `service_definitions`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_servdef_profiles` (`profile_id`);

--
-- Tablo için indeksler `service_jobs`
--
ALTER TABLE `service_jobs`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_servjob_profiles` (`profile_id`),
  ADD KEY `fk_servjob_def` (`service_def_id`);

--
-- Tablo için indeksler `stock_items`
--
ALTER TABLE `stock_items`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `idx_unique_stock` (`profile_id`,`depot_id`,`item_type_name`,`purchase_price_base`,`unique_barcode`);

--
-- Tablo için indeksler `stock_movements`
--
ALTER TABLE `stock_movements`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_moves_profiles` (`profile_id`);

--
-- Tablo için indeksler `taxes`
--
ALTER TABLE `taxes`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_taxes_profile` (`profile_id`);

--
-- Tablo için indeksler `tax_applications`
--
ALTER TABLE `tax_applications`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_tax_app_source` (`source_table`,`source_id`),
  ADD KEY `idx_tax_app_profile` (`profile_id`);

--
-- Tablo için indeksler `tax_profiles`
--
ALTER TABLE `tax_profiles`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_tax_profiles_profile` (`profile_id`);

--
-- Tablo için indeksler `tax_profile_items`
--
ALTER TABLE `tax_profile_items`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniq_profile_tax` (`tax_profile_id`,`tax_id`),
  ADD KEY `idx_tax_profile_items_profile` (`profile_id`),
  ADD KEY `fk_tax_profile_items_tax` (`tax_id`);

--
-- Tablo için indeksler `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_users_profiles` (`profile_id`);

--
-- Tablo için indeksler `user_access_scopes`
--
ALTER TABLE `user_access_scopes`
  ADD KEY `fk_scope_users` (`user_id`);

--
-- Tablo için indeksler `user_permissions`
--
ALTER TABLE `user_permissions`
  ADD PRIMARY KEY (`user_id`,`permission_code`);

--
-- Tablo için AUTO_INCREMENT `global_sync_events`
--
ALTER TABLE `global_sync_events`
  MODIFY `id` bigint NOT NULL AUTO_INCREMENT;

--
-- Dökümü yapılmış tablolar için kısıtlamalar
--

--
-- Tablo kısıtlamaları `app_settings`
--
ALTER TABLE `app_settings`
  ADD CONSTRAINT `fk_settings_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`) ON DELETE CASCADE;

--
-- Tablo kısıtlamaları `audit_logs`
--
ALTER TABLE `audit_logs`
  ADD CONSTRAINT `fk_audit_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`) ON DELETE CASCADE;

--
-- Tablo kısıtlamaları `barcode_history`
--
ALTER TABLE `barcode_history`
  ADD CONSTRAINT `fk_barcode_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`);

--
-- Tablo kısıtlamaları `categories`
--
ALTER TABLE `categories`
  ADD CONSTRAINT `fk_cats_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`) ON DELETE CASCADE;

--
-- Tablo kısıtlamaları `customer_history_events`
--
ALTER TABLE `customer_history_events`
  ADD CONSTRAINT `fk_hist_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`);

--
-- Tablo kısıtlamaları `debt_records`
--
ALTER TABLE `debt_records`
  ADD CONSTRAINT `fk_debt_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`);

--
-- Tablo kısıtlamaları `depots`
--
ALTER TABLE `depots`
  ADD CONSTRAINT `fk_depots_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`);

--
-- Tablo kısıtlamaları `document_counters`
--
ALTER TABLE `document_counters`
  ADD CONSTRAINT `fk_doc_counter_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`) ON DELETE CASCADE;

--
-- Tablo kısıtlamaları `financial_accounts`
--
ALTER TABLE `financial_accounts`
  ADD CONSTRAINT `fk_accounts_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`);

--
-- Tablo kısıtlamaları `financial_transactions`
--
ALTER TABLE `financial_transactions`
  ADD CONSTRAINT `fk_trans_accounts` FOREIGN KEY (`account_id`) REFERENCES `financial_accounts` (`id`),
  ADD CONSTRAINT `fk_trans_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`);

--
-- Tablo kısıtlamaları `persons`
--
ALTER TABLE `persons`
  ADD CONSTRAINT `fk_persons_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`);

--
-- Tablo kısıtlamaları `product_definitions`
--
ALTER TABLE `product_definitions`
  ADD CONSTRAINT `fk_products_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`);

--
-- Tablo kısıtlamaları `repair_records`
--
ALTER TABLE `repair_records`
  ADD CONSTRAINT `fk_repair_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`);

--
-- Tablo kısıtlamaları `sales`
--
ALTER TABLE `sales`
  ADD CONSTRAINT `fk_sales_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`);

--
-- Tablo kısıtlamaları `scheduled_transactions`
--
ALTER TABLE `scheduled_transactions`
  ADD CONSTRAINT `fk_st_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`);

--
-- Tablo kısıtlamaları `service_definitions`
--
ALTER TABLE `service_definitions`
  ADD CONSTRAINT `fk_servdef_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`);

--
-- Tablo kısıtlamaları `service_jobs`
--
ALTER TABLE `service_jobs`
  ADD CONSTRAINT `fk_servjob_def` FOREIGN KEY (`service_def_id`) REFERENCES `service_definitions` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_servjob_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`);

--
-- Tablo kısıtlamaları `stock_items`
--
ALTER TABLE `stock_items`
  ADD CONSTRAINT `fk_stock_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`);

--
-- Tablo kısıtlamaları `stock_movements`
--
ALTER TABLE `stock_movements`
  ADD CONSTRAINT `fk_moves_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`) ON DELETE CASCADE;

--
-- Tablo kısıtlamaları `taxes`
--
ALTER TABLE `taxes`
  ADD CONSTRAINT `fk_taxes_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`) ON DELETE CASCADE;

--
-- Tablo kısıtlamaları `tax_applications`
--
ALTER TABLE `tax_applications`
  ADD CONSTRAINT `fk_tax_app_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`) ON DELETE CASCADE;

--
-- Tablo kısıtlamaları `tax_profiles`
--
ALTER TABLE `tax_profiles`
  ADD CONSTRAINT `fk_tax_profiles_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`) ON DELETE CASCADE;

--
-- Tablo kısıtlamaları `tax_profile_items`
--
ALTER TABLE `tax_profile_items`
  ADD CONSTRAINT `fk_tax_profile_items_profile` FOREIGN KEY (`tax_profile_id`) REFERENCES `tax_profiles` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_tax_profile_items_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_tax_profile_items_tax` FOREIGN KEY (`tax_id`) REFERENCES `taxes` (`id`);

--
-- Tablo kısıtlamaları `users`
--
ALTER TABLE `users`
  ADD CONSTRAINT `fk_users_profiles` FOREIGN KEY (`profile_id`) REFERENCES `profiles` (`id`);

--
-- Tablo kısıtlamaları `user_access_scopes`
--
ALTER TABLE `user_access_scopes`
  ADD CONSTRAINT `fk_scope_users` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;

--
-- Tablo kısıtlamaları `user_permissions`
--
ALTER TABLE `user_permissions`
  ADD CONSTRAINT `fk_perm_users` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE 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 */;



