ソースを参照

Keep working.

Jonatan Gezelius 1 年間 前
コミット
1639a0a4a4

+ 3 - 3
JCL.kicad_dbl

@@ -16,14 +16,14 @@
         {
             "name": "Resistors",
             "table": "kicad_resistors",
-            "key": "internal_pn",
+            "key": "internal_pn_str",
             "symbols": "kicad_symbol",
             "footprints": "kicad_footprint",
             "fields": [
                 {
-                    "column": "internal_pn",
+                    "column": "internal_pn_str",
                     "name": "IPN",
-                    "visible_on_add": true,
+                    "visible_on_add": false,
                     "visible_in_chooser": true,
                     "show_name": true,
                     "inherit_properties": false

+ 2 - 0
python/.gitignore

@@ -0,0 +1,2 @@
+.idea
+venv

+ 206 - 0
python/main.py

@@ -0,0 +1,206 @@
+import mariadb
+import pyodbc
+import math
+
+e24 = [1.0, 1.1, 1.2, 1.3, 1.5, 1.6, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0, 3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5,
+       8.2, 9.1]
+e96 = [1.00, 1.02, 1.05, 1.07, 1.10, 1.13, 1.15, 1.18, 1.21, 1.24, 1.27, 1.30, 1.33, 1.37, 1.40, 1.43, 1.47, 1.50, 1.54,
+       1.58, 1.62, 1.65, 1.69, 1.74, 1.78, 1.82, 1.87, 1.91, 1.96, 2.00, 2.05, 2.10, 2.15, 2.21, 2.26, 2.32, 2.37, 2.43,
+       2.49, 2.55, 2.61, 2.67, 2.74, 2.80, 2.87, 2.94, 3.01, 3.09, 3.16, 3.24, 3.32, 3.40, 3.48, 3.57, 3.65, 3.74, 3.83,
+       3.92, 4.02, 4.12, 4.22, 4.32, 4.42, 4.53, 4.64, 4.75, 4.87, 4.99, 5.11, 5.23, 5.36, 5.49, 5.62, 5.76, 5.90, 6.04,
+       6.19, 6.34, 6.49, 6.65, 6.81, 6.98, 7.15, 7.32, 7.50, 7.68, 7.87, 8.06, 8.25, 8.45, 8.66, 8.87, 9.09, 9.31, 9.53,
+       9.76]
+
+
+def number_to_unit_string(n, unit):
+    # print(f"Nunmber: {n} with unit {unit}")
+    if n != 0:
+        exponent = math.floor(math.log10(n) / 3)
+    else:
+        exponent = 0
+    exponent = min(3, exponent)
+    exponent = max(-5, exponent)
+
+    if exponent <= -5:
+        suffix = 'f'
+    elif exponent == -4:
+        suffix = 'p'
+    elif exponent == -3:
+        suffix = 'n'
+    elif exponent == -2:
+        suffix = 'u'
+    elif exponent == -1:
+        suffix = 'm'
+    elif exponent == 0:
+        suffix = unit
+    elif exponent == 1:
+        suffix = 'k'
+    elif exponent == 2:
+        suffix = 'M'
+    elif exponent >= 3:
+        suffix = 'G'
+
+    adjusted_number = n / (1000 ** exponent)
+    adjusted_number_as_string = f"{adjusted_number:g}"
+    if '.' not in adjusted_number_as_string:
+        string_to_return = adjusted_number_as_string + suffix
+    else:
+        string_to_return = adjusted_number_as_string.replace(".", suffix)
+
+    return string_to_return
+
+
+def number_to_resistance_string(n):
+    return number_to_unit_string(n, 'R')
+
+
+def number_to_capacitance_string(n):
+    return number_to_unit_string(n, 'F')
+
+
+def number_to_inductance_string(n):
+    return number_to_unit_string(n, 'H')
+
+
+def round_to_significant(x, num):
+    round_to = -int(math.floor(math.log10(abs(x)))) + num - 1
+    result = round(x, round_to)
+    # print(f"Rounding {x}, with {round_to}, resulting in {result}")
+    return result
+
+
+def expand_series(series, lowest=1, highest=10):
+    lowest_decade = math.floor(math.log10(lowest))
+    highest_decade = math.ceil(math.log10(highest))
+    values = []
+    for decade in range(lowest_decade, highest_decade + 1):
+        values_to_add = [x * 10 ** decade for x in series if x * 10 ** decade >= lowest and x * 10 ** decade <= highest]
+        values.extend([round_to_significant(x, 3) for x in values_to_add])
+
+    return values
+
+
+resistor_packages = {"01005": {"power": 0.03, "height": 0.15, "length": 0.4, "width": 0.2, "footprint": "R01005",
+                              "symbol": "resistor_2pin"},
+                     "0201": {"power": 0.05, "height": 0.3, "length": 0.6, "width": 0.3, "footprint": "R0201",
+                              "symbol": "resistor_2pin"},
+                     "0402": {"power": 0.062, "height": 0.4, "length": 1.0, "width": 0.5, "footprint": "R0402",
+                              "symbol": "resistor_2pin"},
+                     "0603": {"power": 0.1, "height": 0.5, "length": 1.6, "width": 0.85, "footprint": "R0603",
+                              "symbol": "resistor_2pin"},
+                     "0805": {"power": 0.125, "height": 0.5, "length": 2.0, "width": 1.2, "footprint": "R0805",
+                              "symbol": "resistor_2pin"},
+                     "1206": {"power": 0.25, "height": 0.6, "length": 3.2, "width": 1.6, "footprint": "R1206",
+                              "symbol": "resistor_2pin"},
+                     "1210": {"power": 0.5, "height": 0.6, "length": 3.2, "width": 2.5, "footprint": "R1210",
+                              "symbol": "resistor_2pin"},
+                     "1812": {"power": 1.0, "height": 0.6, "length": 3.2, "width": 4.6, "footprint": "R1812",
+                              "symbol": "resistor_2pin"},
+                     "2010": {"power": 0.75, "height": 0.6, "length": 5.0, "width": 2.5, "footprint": "R1210",
+                              "symbol": "resistor_2pin"},
+                     "2512": {"power": 1.0, "height": 0.6, "length": 6.3, "width": 3.2, "footprint": "R2512",
+                              "symbol": "resistor_2pin"}
+                     }
+
+
+def add_resistors(db_cursor, values, tolerance, package):
+    for value in values:
+        description = f"Resistor, {number_to_resistance_string(value)}, {tolerance * 100}%, SMD, {package}, 100ppm"
+        # print(f"Adding {description}")
+        query_insert_internal_part = f"""
+        INSERT INTO internal_parts (part_description, part_group_id)
+        VALUES
+        ('{description}', 'chip_resistor');"""
+
+        # print(query_insert_internal_part)
+        db_cursor.execute(query_insert_internal_part)
+        # print(f"Warnings: {cur.warnings}")
+        new_part_number = db_cursor.lastrowid
+
+        query_insert_resistor_info = f"""
+        INSERT INTO group_details_chip_resistor (internal_pn, resistance, resistance_tolerance_upper, 
+        resistance_tolerance_lower, `power`, resistor_type, temperature_max, temperature_min, 
+        temperature_coefficient_upper, temperature_coefficient_lower,
+        dimension_height, dimension_length, dimension_width, 
+        component_package, component_symbol)
+        VALUES
+        ({new_part_number}, {value}, {tolerance / 100}, -{tolerance / 100}, {resistor_packages[package]["power"]}, 'Thick Film',
+         155, -55, 100, -100,
+         {resistor_packages[package]["height"]}, {resistor_packages[package]["length"]}, {resistor_packages[package]["width"]},
+         '{resistor_packages[package]["footprint"]}', '{resistor_packages[package]["symbol"]}');"""
+        # print(query_insert_resistor_info)
+        db_cursor.execute(query_insert_resistor_info)
+        # print(f"Warnings: {cur.warnings}")
+    return
+
+
+def main():
+    try:
+        conn = mariadb.connect(
+            user="jegatroncomponents_admin",
+            password="librarian",
+            host="localhost",
+            port=3306,
+            database="jegatroncomponents"
+        )
+    except mariadb.Error as e:
+        print(f"Error connecting to MariaDB Platform: {e}")
+        exit(1)
+
+    db_curr = conn.cursor()
+
+    for package in resistor_packages:
+        print(f"Adding {package} E24 series")
+        add_resistors(db_curr, [0] + expand_series(e24, 0.1, 10000000), 0.05, package)
+        print(f"Adding {package} E96 series")
+        add_resistors(db_curr, [0] + expand_series(e96, 0.1, 10000000), 0.01, package)
+
+    """
+    db_curr.execute("SELECT * from internal_parts;")
+    for k in db_curr:
+        print("Man!")
+        print(k)"""
+
+    conn.commit()
+    db_curr.close()
+    conn.close()
+
+    return
+
+    try:
+        cnxn = pyodbc.connect("Driver={SQL Server Native Client 11.0};"
+                              "Server=db.altiumlibrary.com;"
+                              "Database=altium_library;"
+                              "Trusted_Connection=no;"
+                              "UID=alib_OOMDUPOV4YG1;"
+                              "PWD=e071szxdIu6SnrC6")
+    except Exception as e:
+        print(f"Could not connect to celectial library")
+        print(e)
+        exit(1)
+
+    print("Dude!")
+
+    SQL_QUERY = """
+    SELECT
+    TOP 5
+    *
+    from z_CapacitorsCeramic;
+    """
+    SQL_QUERY = """
+    SELECT *
+    FROM "z_ResistorsSurfaceMount"
+    WHERE Resistance is null;
+    """
+
+    # cur = cnxn.cursor()
+    # cur.execute(SQL_QUERY)
+    """
+    for k in cur:
+        print("Man!")
+        print(k)
+        """
+
+
+if __name__ == '__main__':
+    main()

+ 1 - 0
sql/.gitignore

@@ -0,0 +1 @@
+.dbeaver

+ 1 - 0
sql/.project

@@ -7,5 +7,6 @@
 	<buildSpec>
 	</buildSpec>
 	<natures>
+		<nature>org.jkiss.dbeaver.DBeaverNature</nature>
 	</natures>
 </projectDescription>

+ 19 - 90
sql/Scripts/jegatroncomponents_tests.sql → sql/Scripts/jegatroncomponents_chip_resistor.sql

@@ -1,62 +1,4 @@
 
-/*
-CALL `add_part_group`('krypton', 'Kryptoner', 'En krypton är typiskt dålig för stålmannen');
-CALL `add_part_group`('visp', 'Vispar', 'Med en visp kan man göra smör');
-CALL `add_part_group`('talisman', 'Tasmanska jävlar', 'Det är hittepå');
-CALL `add_part_group`('Oloong', 'Semi-grönt/svart & Te', 'Mellantinget i fermenteringen av teet, brukar förekomma i rullade bollar. Bryggs i 85 grader, 4 minuter.');
-
-
-
-
-CALL add_internal_part('Kinesiskt Oloong', 'Oloong', 'Kinesiskt Oloong som smakar mycket te', @fick_internal_pn); 
-SELECT @fick_internal_pn;
-
-SELECT * 
-FROM internal_parts ip
-JOIN part_groups pg ON ip.part_group_id = pg.part_group_id
-JOIN group_details_oloong gdo ON ip.internal_pn = gdo.internal_pn 
-WHERE ip.internal_pn = 4;
-
-
-SET @part_display_name := 'Token item nr.1';
-SET @part_group_id := 'krypton';
-SET @part_description := 'This token will make thing great again';
-CALL add_internal_part(@part_display_name, @part_group_id, @part_description, @mymandude);
-SELECT @mymandude;
-
-SET @part_display_name := 'Token item nr.2';
-SET @part_group_id := 'krypton';
-CALL add_internal_part(@part_display_name, @part_group_id, @part_description, @mymandude);
-SELECT @mymandude;
-
-SET @part_display_name := 'Token item nr.3';
-SET @part_group_id := 'visp';
-CALL add_internal_part(@part_display_name, @part_group_id, @part_description, @mymandude);
-SELECT @mymandude;
-
-DELETE FROM `internal_parts` WHERE `internal_pn` = 1;
-
-SELECT * 
-FROM `internal_parts` ip
-JOIN `group_details_krypton` gdk ON ip.internal_pn = gdk.internal_pn; 
-*/
-
-CALL `add_part_group`('car', 'Cars', 'Automotive vehicles for transporting people');
-
-ALTER TABLE jegatroncomponents.group_details_car ADD(
-  `series` varchar(100) DEFAULT NULL,
-  `color` varchar(50) NOT NULL,
-  `release_date` timestamp NOT NULL
-);
-
-INSERT INTO manufacturers (mfr) VALUES ('volvo');
-
-
-INSERT INTO manufacturer_parts (mpn, mfr, part_group_id, part_description, lifecycle_status)
-VALUES ('S60', 'volvo', 'car', 'A good car', 'Obsolete'),
-('S80', 'volvo', 'car', 'A bigger good car', 'Obsolete');
-
-
 CALL `add_part_group`('chip_resistor', 'Chip Resistor - SMD', 'Surface mount resistors');
 
 ALTER TABLE jegatroncomponents.group_details_chip_resistor ADD(
@@ -89,7 +31,7 @@ IF NEW.`resistance_str` IS NULL THEN
  SET NEW.resistance_str := to_value_string(NEW.resistance, 'R');
 END IF;
 //
-CREATE OR REPLACE TRIGGER add_resistance_str
+CREATE OR REPLACE TRIGGER update_resistance_str
 BEFORE UPDATE ON jegatroncomponents.group_details_chip_resistor
 FOR EACH ROW 
 IF NEW.`resistance_str` IS NULL THEN
@@ -98,21 +40,6 @@ END IF;
 //
 delimiter ;
 
-DROP VIEW IF EXISTS kicad_resistors;
-CREATE OR REPLACE VIEW kicad_resistors
-AS
-SELECT ip.internal_pn, to_pn_string(ip.internal_pn) AS internal_pn_string, ip.part_description AS description, gdcr.resistance AS value,
- cp.package_display_name, ip.exclude_from_bom, ip.exclude_from_board, fk.kicad_footprint,
- fk.kicad_footprint_filter, sk.kicad_symbol,
- gdcr.resistance_str AS value_str
-FROM internal_parts ip
-JOIN group_details_chip_resistor gdcr ON ip.internal_pn = gdcr.internal_pn
-JOIN component_packages cp ON gdcr.component_package = cp.component_package
-LEFT JOIN footprints_kicad fk ON gdcr.component_package = fk.component_package 
-LEFT JOIN symbols_kicad sk ON gdcr.component_symbol = sk.component_symbol;
-
-# SELECT * FROM kicad_resistors kr ;
-
 
 INSERT INTO manufacturers (mfr) VALUES ('yageo');
 INSERT INTO manufacturers (mfr) VALUES ('tdk');
@@ -129,14 +56,7 @@ VALUES
 ('R1210', '1210 (3225 Metric)'),
 ('R1812', '1812 (4532 Metric)'),
 ('R2010', '2010 (5025 Metric)'),
-('R2512', '2512 (6332 Metric)'),
-('C01005', '01005 (0402 Metric)'),
-('C0201', '0201 (0603 Metric)'),
-('C0402', '0402 (1010 Metric)'),
-('C0603', '0603 (1608 Metric)'),
-('C0805', '0805 (2012 Metric)'),
-('C1206', '1206 (3216 Metric)'),
-('C1210', '1210 (3225 Metric)')
+('R2512', '2512 (6332 Metric)')
 ON duplicate KEY UPDATE package_display_name = package_display_name;
 
 DELETE FROM footprints_kicad ;
@@ -151,14 +71,7 @@ VALUES
 ('R1210', 'Resistor_SMD:R_1210_3225Metric', 'Resistor_SMD:R_1210_*'),
 ('R1812', 'Resistor_SMD:R_1812_4532Metric', 'Resistor_SMD:R_1812_*'),
 ('R2010', 'Resistor_SMD:R_2010_5025Metric', 'Resistor_SMD:R_2010_*'),
-('R2512', 'Resistor_SMD:R_2512_6332Metric', 'Resistor_SMD:R_2512_*'),
-('C01005', 'Capacitor_SMD:R_01005_0402Metric', 'Capacitor_SMD:R_01005_*'),
-('C0201', 'Capacitor_SMD:R_0201_0603Metric', 'Capacitor_SMD:R_0201_*'),
-('C0402', 'Capacitor_SMD:R_0402_1010Metric', 'Capacitor_SMD:R_0402_*'),
-('C0603', 'Capacitor_SMD:R_0603_1608Metric', 'Capacitor_SMD:R_0603_*'),
-('C0805', 'Capacitor_SMD:R_0805_2012Metric', 'Capacitor_SMD:R_0805_*'),
-('C1206', 'Capacitor_SMD:R_1206_3216Metric', 'Capacitor_SMD:R_1206_*'),
-('C1210', 'Capacitor_SMD:R_1210_3225Metric', 'Capacitor_SMD:R_1210_*')
+('R2512', 'Resistor_SMD:R_2512_6332Metric', 'Resistor_SMD:R_2512_*')
 ON duplicate KEY UPDATE kicad_footprint = kicad_footprint;
 
 
@@ -173,3 +86,19 @@ VALUES
 ('capacitor_2pin', 'Device:C');
 
 
+
+DROP VIEW IF EXISTS kicad_resistors;
+CREATE OR REPLACE VIEW kicad_resistors
+AS
+SELECT ip.internal_pn, internal_pn_str, ip.part_description AS description, gdcr.resistance AS value,
+ cp.package_display_name, ip.exclude_from_bom, ip.exclude_from_board, fk.kicad_footprint,
+ fk.kicad_footprint_filter, sk.kicad_symbol,
+ gdcr.resistance_str AS value_str
+FROM internal_parts ip
+JOIN group_details_chip_resistor gdcr ON ip.internal_pn = gdcr.internal_pn
+JOIN component_packages cp ON gdcr.component_package = cp.component_package
+LEFT JOIN footprints_kicad fk ON gdcr.component_package = fk.component_package 
+LEFT JOIN symbols_kicad sk ON gdcr.component_symbol = sk.component_symbol
+WHERE ip.part_group_id = 'chip_resistor';
+
+SELECT * FROM kicad_resistors kr ORDER BY internal_pn DESC;

+ 28 - 50
sql/Scripts/jegatroncomponents_recreate.sql

@@ -52,12 +52,12 @@ SET FOREIGN_KEY_CHECKS=1;
 -- Finished removing everything
 
 /* Debug table to store whatever in */
-/*
+
 CREATE TABLE `debug_msg` (
 msg_id int PRIMARY KEY AUTO_INCREMENT,
 msg text
 );
-*/
+
 
 /* Contains listing of part groups. Each group should have a dedicated
  * table containing part group specific details. */
@@ -87,6 +87,7 @@ BEGIN
 		`internal_pn` int DEFAULT NULL,
 		CONSTRAINT `', @table_name, '_part_FK` FOREIGN KEY (`internal_pn`) REFERENCES `internal_parts` (`internal_pn`) ON DELETE CASCADE,
 		CONSTRAINT `', @table_name, '_part_AK` UNIQUE (`internal_pn`),
+		`internal_pn_str` varchar(9) DEFAULT NULL,
 		`mpn` varchar(50) DEFAULT NULL,
 		`mfr` varchar(50) DEFAULT NULL,
 		CONSTRAINT `', @table_name, '_mpn_FK` FOREIGN KEY (`mpn`, `mfr`) REFERENCES `manufacturer_parts` (`mpn`, `mfr`) ON DELETE CASCADE ON UPDATE CASCADE,
@@ -97,6 +98,24 @@ BEGIN
 	-- INSERT INTO `debug_msg`(`msg`) VALUES (@create_detail_table_query);
 
 	EXECUTE IMMEDIATE @create_detail_table_query;
+
+	SET @create_trigger_a := concat('
+		CREATE OR REPLACE TRIGGER ', @table_name, '_add_pn_str
+		BEFORE INSERT ON `', @table_name, '`
+		FOR EACH ROW 
+		 SET NEW.internal_pn_str := to_pn_string(NEW.internal_pn);');
+	-- INSERT INTO `debug_msg`(`msg`) VALUES (@create_trigger_a);
+	EXECUTE IMMEDIATE @create_trigger_a;
+
+	SET @create_triggers_b := concat('
+		CREATE OR REPLACE TRIGGER ', @table_name, '_update_pn_str
+		BEFORE UPDATE ON `', @table_name, '`
+		FOR EACH ROW 
+		 SET NEW.internal_pn_str := to_pn_string(NEW.internal_pn);');
+	-- INSERT INTO `debug_msg`(`msg`) VALUES (@create_triggers_b);
+	EXECUTE IMMEDIATE @create_triggers_b;
+
+
 	 
 END;
 //
@@ -129,30 +148,6 @@ END
 //
 delimiter ;
 
-/* Helper function for adding internal components
- * It creates a row in internal parts table and a row in the corresponding details table */
-/*
-DELIMITER //
-CREATE OR REPLACE PROCEDURE `add_internal_part`(
- IN part_display_name varchar(50),
- IN part_group_id varchar(50),
- IN part_description text,
- OUT internal_pn int)
-BEGIN
-	SELECT pg.part_group_detail_table INTO @table_name FROM `part_groups` pg WHERE pg.part_group_id = part_group_id;
-
-	INSERT INTO `internal_parts` (`part_display_name`, `part_group_id`, `part_description`) VALUES (part_display_name, part_group_id, part_description);
-	SET @last_id := last_insert_id();
-	SET internal_pn := @last_id;
-	SET @part_detail_query := concat('INSERT INTO `', @table_name, '` (`internal_pn`) VALUES (', @last_id, ')');
-	-- SELECT @part_detail_query;
-	EXECUTE IMMEDIATE @part_detail_query;
-	 
-END;
-//
-DELIMITER ;
-*/
-
 CREATE TABLE `manufacturers` (
   `mfr` varchar(50) NOT NULL,
   `mfr_display_name` varchar(100) DEFAULT NULL,
@@ -174,28 +169,6 @@ CREATE TABLE `manufacturer_parts` (
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
 
 
-/* Helper function for adding manufacturer components
- * It creates a row in internal parts table and a row in the corresponding details table */
-/*
-DELIMITER //
-CREATE OR REPLACE PROCEDURE `add_manufacturer_part`(
- IN mpn varchar(50),
- IN mfr varchar(50),
- IN part_group_id varchar(50),
- IN part_description text)
-BEGIN
-	SELECT pg.part_group_detail_table INTO @table_name FROM `part_groups` pg WHERE pg.part_group_id = part_group_id;
-
-	INSERT INTO `manufacturer_parts` (`mpn`, `mfr`, `part_group_id`, `part_description`) VALUES (mpn, mfr, part_group_id, part_description);
-	SET @part_detail_query := concat('INSERT INTO `', @table_name, '` (`mpn`, `mfr`) VALUES (\'', mpn , '\', \'', mfr, '\' )');
-	-- SELECT @part_detail_query;
-	EXECUTE IMMEDIATE @part_detail_query;
-	 
-END;
-//
-DELIMITER ;
-*/
-
 CREATE TABLE `qualified_parts` (
   `internal_pn` int(11) NOT NULL,
   `mpn` varchar(50) NOT NULL,
@@ -269,8 +242,13 @@ BEGIN
  DECLARE exponent int;
  DECLARE suffix varchar(2);
  DECLARE string_to_return varchar(10);
- 
- SET exponent = floor(log10(n)/3);
+
+ IF n != 0 THEN
+  SET exponent = floor(log10(n)/3);
+ ELSE
+  SET exponent = 0;
+ END IF;
+
  SET exponent = greatest(-5, exponent);
  SET exponent = least(3, exponent);
 

+ 27 - 0
sql/Scripts/jegatroncomponents_smd_ceramic_cap.sql

@@ -0,0 +1,27 @@
+INSERT INTO component_packages (component_package, package_display_name)
+VALUES
+('C01005', '01005 (0402 Metric)'),
+('C0201', '0201 (0603 Metric)'),
+('C0402', '0402 (1010 Metric)'),
+('C0603', '0603 (1608 Metric)'),
+('C0805', '0805 (2012 Metric)'),
+('C1206', '1206 (3216 Metric)'),
+('C1210', '1210 (3225 Metric)'),
+('C1812', '1812 (4532 Metric)'),
+('C2010', '2010 (5025 Metric)'),
+('C2512', '2512 (6332 Metric)')
+ON duplicate KEY UPDATE package_display_name = package_display_name;
+
+INSERT INTO footprints_kicad (component_package, kicad_footprint, kicad_footprint_filter)
+VALUES
+('C01005', 'Capacitor_SMD:C_01005_0402Metric', 'Capacitor_SMD:C_01005_*'),
+('C0201', 'Capacitor_SMD:C_0201_0603Metric', 'Capacitor_SMD:C_0201_*'),
+('C0402', 'Capacitor_SMD:C_0402_1010Metric', 'Capacitor_SMD:C_0402_*'),
+('C0603', 'Capacitor_SMD:C_0603_1608Metric', 'Capacitor_SMD:C_0603_*'),
+('C0805', 'Capacitor_SMD:C_0805_2012Metric', 'Capacitor_SMD:C_0805_*'),
+('C1206', 'Capacitor_SMD:C_1206_3216Metric', 'Capacitor_SMD:C_1206_*'),
+('C1210', 'Capacitor_SMD:C_1210_3225Metric', 'Capacitor_SMD:C_1210_*'),
+('R1812', 'Capacitor_SMD:C_1812_4532Metric', 'Capacitor_SMD:C_1812_*'),
+('R2010', 'Capacitor_SMD:C_2010_5025Metric', 'Capacitor_SMD:C_2010_*'),
+('R2512', 'Capacitor_SMD:C_2512_6332Metric', 'Capacitor_SMD:C_2512_*')
+ON duplicate KEY UPDATE kicad_footprint = kicad_footprint;

+ 57 - 0
sql/Scripts/jegatroncomponents_test.sql

@@ -0,0 +1,57 @@
+
+/*
+CALL `add_part_group`('krypton', 'Kryptoner', 'En krypton är typiskt dålig för stålmannen');
+CALL `add_part_group`('visp', 'Vispar', 'Med en visp kan man göra smör');
+CALL `add_part_group`('talisman', 'Tasmanska jävlar', 'Det är hittepå');
+CALL `add_part_group`('Oloong', 'Semi-grönt/svart & Te', 'Mellantinget i fermenteringen av teet, brukar förekomma i rullade bollar. Bryggs i 85 grader, 4 minuter.');
+
+
+
+
+CALL add_internal_part('Kinesiskt Oloong', 'Oloong', 'Kinesiskt Oloong som smakar mycket te', @fick_internal_pn); 
+SELECT @fick_internal_pn;
+
+SELECT * 
+FROM internal_parts ip
+JOIN part_groups pg ON ip.part_group_id = pg.part_group_id
+JOIN group_details_oloong gdo ON ip.internal_pn = gdo.internal_pn 
+WHERE ip.internal_pn = 4;
+
+
+SET @part_display_name := 'Token item nr.1';
+SET @part_group_id := 'krypton';
+SET @part_description := 'This token will make thing great again';
+CALL add_internal_part(@part_display_name, @part_group_id, @part_description, @mymandude);
+SELECT @mymandude;
+
+SET @part_display_name := 'Token item nr.2';
+SET @part_group_id := 'krypton';
+CALL add_internal_part(@part_display_name, @part_group_id, @part_description, @mymandude);
+SELECT @mymandude;
+
+SET @part_display_name := 'Token item nr.3';
+SET @part_group_id := 'visp';
+CALL add_internal_part(@part_display_name, @part_group_id, @part_description, @mymandude);
+SELECT @mymandude;
+
+DELETE FROM `internal_parts` WHERE `internal_pn` = 1;
+
+SELECT * 
+FROM `internal_parts` ip
+JOIN `group_details_krypton` gdk ON ip.internal_pn = gdk.internal_pn; 
+*/
+
+CALL `add_part_group`('car', 'Cars', 'Automotive vehicles for transporting people');
+
+ALTER TABLE jegatroncomponents.group_details_car ADD(
+  `series` varchar(100) DEFAULT NULL,
+  `color` varchar(50) NOT NULL,
+  `release_date` timestamp NOT NULL
+);
+
+INSERT INTO manufacturers (mfr) VALUES ('volvo');
+
+
+INSERT INTO manufacturer_parts (mpn, mfr, part_group_id, part_description, lifecycle_status)
+VALUES ('S60', 'volvo', 'car', 'A good car', 'Obsolete'),
+('S80', 'volvo', 'car', 'A bigger good car', 'Obsolete');