|
|
@@ -1,80 +0,0 @@
|
|
1
|
|
-'use strict';
|
|
2
|
|
-
|
|
3
|
|
-/** @type {import('sequelize-cli').Migration} */
|
|
4
|
|
-module.exports = {
|
|
5
|
|
- async up (queryInterface, Sequelize) {
|
|
6
|
|
- // Check if candles_1h table exists
|
|
7
|
|
- const tableExists = await queryInterface.sequelize.query(
|
|
8
|
|
- "SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name = 'candles_1h');",
|
|
9
|
|
- { type: Sequelize.QueryTypes.SELECT }
|
|
10
|
|
- );
|
|
11
|
|
-
|
|
12
|
|
- if (!tableExists || !tableExists[0] || !tableExists[0].exists) {
|
|
13
|
|
- console.log('Table candles_1h does not exist, skipping migration. Tables will be created by model sync with timeframe support.');
|
|
14
|
|
- return;
|
|
15
|
|
- }
|
|
16
|
|
-
|
|
17
|
|
- // Rename table from candles_1h to candles
|
|
18
|
|
- await queryInterface.renameTable('candles_1h', 'candles');
|
|
19
|
|
-
|
|
20
|
|
- // Add timeframe column with enum
|
|
21
|
|
- await queryInterface.addColumn('candles', 'timeframe', {
|
|
22
|
|
- type: Sequelize.ENUM('15m', '30m', '1h', '1D', '1W', '1M'),
|
|
23
|
|
- allowNull: false,
|
|
24
|
|
- defaultValue: '1h'
|
|
25
|
|
- });
|
|
26
|
|
-
|
|
27
|
|
- // Update existing records to have '1h' timeframe
|
|
28
|
|
- await queryInterface.sequelize.query('UPDATE candles SET timeframe = \'1h\' WHERE timeframe IS NULL');
|
|
29
|
|
-
|
|
30
|
|
- // Remove the default value after setting existing records
|
|
31
|
|
- await queryInterface.changeColumn('candles', 'timeframe', {
|
|
32
|
|
- type: Sequelize.ENUM('15m', '30m', '1h', '1D', '1W', '1M'),
|
|
33
|
|
- allowNull: false
|
|
34
|
|
- });
|
|
35
|
|
-
|
|
36
|
|
- // Drop the old unique constraint
|
|
37
|
|
- await queryInterface.removeConstraint('candles', 'unique_symbol_open_time');
|
|
38
|
|
-
|
|
39
|
|
- // Add new unique constraint including timeframe
|
|
40
|
|
- await queryInterface.addConstraint('candles', {
|
|
41
|
|
- fields: ['symbol_id', 'open_time', 'timeframe'],
|
|
42
|
|
- type: 'unique',
|
|
43
|
|
- name: 'unique_symbol_open_time_timeframe'
|
|
44
|
|
- });
|
|
45
|
|
-
|
|
46
|
|
- // Update indexes to include timeframe
|
|
47
|
|
- await queryInterface.removeIndex('candles', 'idx_candles_open_time');
|
|
48
|
|
- await queryInterface.addIndex('candles', ['open_time', 'timeframe'], {
|
|
49
|
|
- name: 'idx_candles_open_time_timeframe'
|
|
50
|
|
- });
|
|
51
|
|
- },
|
|
52
|
|
-
|
|
53
|
|
- async down (queryInterface, Sequelize) {
|
|
54
|
|
- // Reverse the changes
|
|
55
|
|
-
|
|
56
|
|
- // Remove new indexes
|
|
57
|
|
- await queryInterface.removeIndex('candles', 'idx_candles_open_time_timeframe');
|
|
58
|
|
-
|
|
59
|
|
- // Add back old index
|
|
60
|
|
- await queryInterface.addIndex('candles', ['open_time'], {
|
|
61
|
|
- name: 'idx_candles_open_time'
|
|
62
|
|
- });
|
|
63
|
|
-
|
|
64
|
|
- // Remove new constraint
|
|
65
|
|
- await queryInterface.removeConstraint('candles', 'unique_symbol_open_time_timeframe');
|
|
66
|
|
-
|
|
67
|
|
- // Add back old constraint
|
|
68
|
|
- await queryInterface.addConstraint('candles', {
|
|
69
|
|
- fields: ['symbol_id', 'open_time'],
|
|
70
|
|
- type: 'unique',
|
|
71
|
|
- name: 'unique_symbol_open_time'
|
|
72
|
|
- });
|
|
73
|
|
-
|
|
74
|
|
- // Remove timeframe column
|
|
75
|
|
- await queryInterface.removeColumn('candles', 'timeframe');
|
|
76
|
|
-
|
|
77
|
|
- // Rename table back to candles_1h
|
|
78
|
|
- await queryInterface.renameTable('candles', 'candles_1h');
|
|
79
|
|
- }
|
|
80
|
|
-};
|